Reputation: 447
I have string like this
string asd = "PT. Mitra Adiperkasa Tbk 01.710.880.4-054.000 Wisma 46 Kota BNI Lt. 8 Jl Jend Sudirman Kav 1, Jak Pus "
with really long space
how can I divide each sentence into a different string like this
string asd1 = "PT. Mitra Adiperkasa Tbk"
string asd2 = "01.710.880.4-054.000"
string asd3 = "Wisma 46 Kota BNI Lt. 8"
string asd4 = "Jl Jend Sudirman Kav 1, Jak Pus"
Upvotes: 0
Views: 277
Reputation: 58
string abc = "abc def ghi";
string[]xyz= System.Text.RegularExpressions.Regex.Split(abc, @"\s{2,}");
System.Console.WriteLine(xyz[0]);
System.Console.WriteLine(xyz[1]);
Try using this code
Upvotes: 3
Reputation: 4355
How about like this? Split by 2 spaces or a tab.
static void Main(string[] args)
{
string asd = "PT. Mitra Adiperkasa Tbk 01.710.880.4-054.000 Wisma 46 Kota BNI Lt. 8 Jl Jend Sudirman Kav 1, Jak Pus ";
foreach (string s in asd.Trim().Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries))
{
Console.WriteLine(s);
}
Console.ReadKey();
}
Upvotes: 2