This is a discussion on How to split a string by using a string usually in the c# dotnet... within the C# Programming forums, part of the Software Development category; How to split a string by using a string.Usually in the c# DOT NET, we can only split a ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi...Using the below method, one can split the string by a string value very easily. private string[] SplitByString(string testString, string split) { int offset = 0; int index = 0; int[] offsets = new int[testString.Length + 1]; while (index < testString.Length) { int indexOf = testString.IndexOf(split, index); if (indexOf != -1) { offsets[offset++] = indexOf; index = (indexOf + split.Length); } else { index = testString.Length; } } string[] final = new string[offset + 1]; if (offset == 0) { final[0] = testString; } else { offset--; final[0] = testString.Substring(0, offsets[0]); for (int i = 0; i < offset; i++) { final[i + 1] = testString.Substring(offsets[i] + split.Length, offsets[i + 1] - offsets[i] - split.Length); } final[offset + 1] = testString.Substring(offsets[offset] + split.Length); } return final; } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert String to Date: new Date(string) | oxygen | Flash Actionscript Programming | 3 | 03-07-2008 09:24 PM |
| String | Kirubhananth | ASP and ASP.NET Programming | 2 | 02-25-2008 09:37 PM |
| Compare a string with String Array. | oxygen | C# Programming | 5 | 12-28-2007 11:18 PM |
| What is diffrenece between string.compare and string.compareordinal | shaalini | ASP and ASP.NET Programming | 3 | 12-28-2007 10:46 PM |
| Encoding String | Anandavinayagam | PHP Programming | 0 | 03-29-2007 12:49 AM |