用字符串分割字符串 C# .net 1.1.4322
如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 @"\|\|\|" 怎么样?在您的 Regex.Split 调用中?这使得|字符 文字字符。
What about using @"\|\|\|" in your Regex.Split call? That makes the | characters literal characters.
一种解决方法是替换和拆分:
One workaround is replace and split:
这是一个例子:
here is an example: