Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum ➡ Separating the Fields Inside a String ♦
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // aljodav // http://rextester.com/users/376 // reply to the MSDN forum thread // http://bit.ly/2fNrmGu namespace Rextester { public class Program { public static void Main(string[] args) { string data="Name:John Joan Peter Paul Mary Pincode:4001-655 & 1004-556 and also 123-456-789-00 DOB:12/02/1976 or maybe 02/12/1976, or even some other date Location:Miami Beach, Florida, USA"; Console.WriteLine("The whole string:\n\n{0}\n\n\nThe string by fields:\n",data); data .Split(new[]{' '},StringSplitOptions.RemoveEmptyEntries) .Aggregate(new List<string>(),(list,split)=>{ if(split.Contains(':')){ list.Add(split); }else{ list[-1+list.Count]+=" "+split; } return list; }) .ForEach(Console.WriteLine) ; Console.WriteLine("\n\nHello, world!"); } } }
run
|
edit
|
history
|
help
0
ArrayList list merge_collections
Unity First Person Controller
delete_xml_empty_tags
Get Combined Placeholder Settings and New Content Length
Lexicon
⁸
Generics
svitch
Difference between Equals and ==
sdfghjkilujyht