我有一个字符串“pc1 | pc2 | pc3 |”
我希望将每个单词放在不同的行上,如:
PC1
PC2
PC3
我需要在C#中执行此操作...
任何建议??
答案 0 :(得分:12)
string[] parts = s.Split(new [] {'|'}, StringSplitOptions.RemoveEmptyEntries);
foreach (string part in parts)
Console.WriteLine(part);
答案 1 :(得分:4)
string withNewLines = original.Replace("|", Environment.NewLine);
答案 2 :(得分:4)
var parts = s.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string word in parts)
{
Console.WriteLine(word);
}
答案 3 :(得分:1)
string s = "pc1|pc2|pc3|";
string[] words = s.Split('|');
答案 4 :(得分:0)
string words[] = string.Split("|");
foreach (string word in words)
{
Console.WriteLine(word);
}
答案 5 :(得分:0)
string fullString = "pc1|pc2|pc3|";
foreach (string pc in fullString.Split('|'))
Console.WriteLine(pc);