Reputation: 4630
I have a string "pc1|pc2|pc3|"
I want to get each word on different line like:
pc1
pc2
pc3
I need to do this in C#...
any suggestions??
Upvotes: 0
Views: 288
Reputation: 171814
string[] parts = s.Split(new [] {'|'}, StringSplitOptions.RemoveEmptyEntries);
foreach (string part in parts)
Console.WriteLine(part);
Upvotes: 12
Reputation: 6046
string fullString = "pc1|pc2|pc3|";
foreach (string pc in fullString.Split('|'))
Console.WriteLine(pc);
Upvotes: 0
Reputation: 48265
var parts = s.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string word in parts)
{
Console.WriteLine(word);
}
Upvotes: 4
Reputation: 2687
string words[] = string.Split("|");
foreach (string word in words)
{
Console.WriteLine(word);
}
Upvotes: 0