Question : Split String in C#

Hi

I have a string like this
77/4, Nandidurga Road $ Krishna Durga Apts. 3Rd Floor $  $

I need a common C# public function to return output as follows

Address1 = 77/4, Nandidurga Road
Address2 = Krishna Durga Apts. 3Rd Floor
Address3 =
address4=

3 & 4 is blank because there is no data after delimiter $. If there is data it may return the same for respective variables

Answer : Split String in C#

Might want to add Trim() and some range checking to Dhaest's solution

string[] words = s.Split('$');

Address1 = words[0].Trim();
Address2 = (words.Length > 1) ? words[1].Trim() : "";
Address3 = (words.Length > 2) ? words[2].Trim() : "";
Address4 = (words.Length > 3) ? words[3].Trim() : "";
Random Solutions  
 
programming4us programming4us