Answer the question
In order to leave comments, you need to log in
How to cut text before and after a certain word?
There is text:
"Class: Warrior
Weapon: Ax
Strength: 55"
How can I cut the text so that only "Weapon: Axe" remains?
Answer the question
In order to leave comments, you need to log in
If you want to trim certain characters, you can use Trim (), the beginning of the text through Contains, the end and the beginning can still be through text.Substring. Again, this is if you don't need to search for a specific character or word to trim against.
In your case, does the text before and after have the same number of characters?
How to cut text before and after a certain word?You understand that only this word will remain.
Weapon: Axe
in your example. This is the result.
string phrase = @"Class: Warrior
Weapon: Axe
Strength: 55";
string[] words = phrase.Split(Environment.NewLine.ToCharArray());
Console.WriteLine(words[1]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question