用字符串分割字符串 C# .net 1.1.4322

发布于 2024-08-20 21:20:30 字数 494 浏览 4 评论 0原文

如何在 C# .net 1.1.4322 中用字符串拆分字符串?

字符串示例:

Key|Value|||Key|Value|||Key|Value|||Key|Value

need:

Key|Value
Key|Value
Key|Value
  • 我无法使用 RegEx.Split,因为分隔字符是 |||并分别获取每个字符。

  • 我无法使用 String.Split() 重载,因为它不在 .net 1.1 中

接受的解决方案示例:< /强>

using System.Text.RegularExpressions;

String[] values = Regex.Split(stringToSplit,"\\|\\|\\|");

How do I split a string with a string in C# .net 1.1.4322?

String example:

Key|Value|||Key|Value|||Key|Value|||Key|Value

need:

Key|Value
Key|Value
Key|Value
  • I cannot use the RegEx.Split because the separating character is the ||| and just get every character separately.

  • I cannot use the String.Split() overload as its not in .net 1.1

Example of Accepted solution:

using System.Text.RegularExpressions;

String[] values = Regex.Split(stringToSplit,"\\|\\|\\|");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

巷子口的你 2024-08-27 21:20:31

使用 @"\|\|\|" 怎么样?在您的 Regex.Split 调用中?这使得|字符 文字字符。

What about using @"\|\|\|" in your Regex.Split call? That makes the | characters literal characters.

海的爱人是光 2024-08-27 21:20:31

一种解决方法是替换和拆分:

string[] keyvalues = "key|value|||key|value".replace("|||", "~").split('~');

One workaround is replace and split:

string[] keyvalues = "key|value|||key|value".replace("|||", "~").split('~');
池木 2024-08-27 21:20:31

这是一个例子:

System.Collections.Hashtable table;
string[] items = somestring.split("|||");
foreach(string item in items)
{
   string[] keyvalue = item.split("|");
   table.add(keyvalue[0],keyvalue[1]);
}

here is an example:

System.Collections.Hashtable table;
string[] items = somestring.split("|||");
foreach(string item in items)
{
   string[] keyvalue = item.split("|");
   table.add(keyvalue[0],keyvalue[1]);
}
相对绾红妆 2024-08-27 21:20:31
string input = "Hi#*#Hello#*#i#*#Hate#*#My#*#......" ;
string[] delim = new string[] { "#*#" };
string[] results = input.split(delim , StringSplitOptions.None); 
string input = "Hi#*#Hello#*#i#*#Hate#*#My#*#......" ;
string[] delim = new string[] { "#*#" };
string[] results = input.split(delim , StringSplitOptions.None); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文