Can anyone please describe me how we can i split few text in any string ??? in C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can anyone please describe me how we can i split few text in any string ??? in C#

I want to try to split text using split method but its not properly cut, can any one tell me how it be possible? string text ="The quick fox over Jump then lazy dog"; i need to cut between words- "over jump" and i want method dynamic not static.

12th Jun 2022, 2:39 AM
Rahul Chauhan
Rahul Chauhan - avatar
3 Answers
+ 4
Rahul Chauhan , a basic approach could be: -> take the text that should be split and search for the word that follows the split podition we can use string method .IndexOf(<word>) this returns the index to te first char of the word -> get the first part of the string by using string method .Substring(<start>, <end>) where <start> is 0, <end> is the index position -> get the second part of the string, we can can also use .Substring(<start>) where <start> is the index position. since we wanted the string up to its end, no argument is required
13th Jun 2022, 5:59 PM
Lothar
Lothar - avatar
+ 3
You did not really specify the logic how you want to split your string dynamically. As an example, you can find the first occurrence of the substring Jump in the text with IndexOf method, then extract the first and second part using the Substring method. https://docs.microsoft.com/en-us/dotnet/csharp/how-to/search-strings https://www.geeksforgeeks.org/c-sharp-string/ As a more general approach you can use regular expressions.
12th Jun 2022, 12:42 PM
Tibor Santa
Tibor Santa - avatar
+ 2
Can you add your code from the code playground here? Then someone can help you more easily.
12th Jun 2022, 12:36 PM
Ausgrindtube
Ausgrindtube - avatar