Answer the question
In order to leave comments, you need to log in
How to parse tex in such conditions?
There is an example text
куча текста , с разными знаками и символами {/.;sas slovo ,dasuwjqaas} и ешё большая куча всякого разного
Answer the question
In order to leave comments, you need to log in
A string is an array of characters.
1. Using the IndexOf() method, we look for the first occurrence of the characters '{' and '}'
2. Using the SubString() method, we store the text between the found indices.
3. We return to point 1, but we start the search with the character after the '}'.
4. Repeat until one of the IndexOf() methods returns -1.
In general, to solve this problem, it is better to smoke regular seasons.
private static List<string> ParseString(string input)
{
List<string> result = new List<string>();
int openIndex = input.IndexOf('{');
int closeIndex = input.IndexOf('}');
while (openIndex != -1 && closeIndex != -1)
{
result.Add(input.Substring(openIndex, closeIndex - openIndex + 1));
input = input.Substring(closeIndex + 1);
openIndex = input.IndexOf('{');
closeIndex = input.IndexOf('}');
}
return result;
}
private static List<string> ParseStringRegex(string input)
{
Regex regex = new Regex(@"{([\s\S]+?)}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
var matches = regex.Matches(input);
return matches.Select(m => m.Value).ToList();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question