⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 C#开发教程 由浅入深 配有实例 是初学者的好帮手
💻 CS
字号:
using System;
using System.Text.RegularExpressions;

namespace SplitRegEx
{
	class SplitRegExApp
	{
		[STAThread]
		static void Main(string[] args)
		{
			string s = "Once Upon A Time In America";
//			char[] seps = new char[]{' '};
			Regex r = new Regex(" ");
//			foreach (string ss in s.Split(seps))
			foreach (string ss in r.Split(s))
			{
				Console.WriteLine(ss);
			}

			Console.WriteLine(
				"\nMultiple different delimiters:");
			string t = "Once,Upon:A/Time\\In\'America";
//			char[] sep2 = new char[]{
//				' ', ',', ':', '/', '\\', '\''};
			Regex q = new Regex(@" |,|:|/|\\|\'");
//			foreach (string ss in t.Split(sep2))
			foreach (string ss in q.Split(t))
			{
				Console.WriteLine(ss);
			}

			Console.WriteLine(
				"\nMultiple spaces, using \" \"");
			string u = "Once   Upon A Time In   America";
			Regex p = new Regex(" ");
			foreach (string ss in p.Split(u))
			{
				if (ss.Length > 0)
					Console.WriteLine(ss);
			}

			Console.WriteLine(
				"\nMultiple spaces, using \"[\\s]+\"");
			string v = "Once   Upon A Time In   America";
			Regex o = new Regex(@"[\s]+");
			foreach (string ss in o.Split(v))
			{
				Console.WriteLine(ss);
			}

			Console.WriteLine(
				"\nMultiple spaces, using \"[ ]+\"");
			string w = "Once   Upon A Time In   America";
			Regex n = new Regex("[ ]+");
			foreach (string ss in n.Split(w))
			{
				Console.WriteLine(ss);
			}

			Console.WriteLine(
				"\nSingle spaces, using ()");
			string x = "Once Upon A Time In America";
			Regex m = new Regex("( )");
			foreach (string ss in m.Split(x))
			{
				Console.WriteLine(ss);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -