.NET Developers' Reference Card Round-Up
posted by adammal(0) 3 years, 10 months ago 0
Sorry Alvin, i couldn't see your Reference Card. :( @sukhjinder82 I'm not sure this is an appropriate place for this kind of question but in the interest of helping out a fellow programmer here is one of the many ways you could solve this problem. public static string SplitTheString(string theString) { // Argument Check if (string.IsNullOrEmpty(theString)) { return theString; } // Define the token to split the string on. string splitToken = "_"; // Split the string using the "_" token string[] splits = theString.Split(new string[] {splitToken}, StringSplitOptions.None); // if splits have been found then return the first split together with the original token. if (splits != null && splits.Length > 0) { return splits[0] + splitToken; } // no split was found, just return the original string. return theString; }
Reply