Index of end of line in undefined length of string

I’m trying to find the index of EOL or the enter key in a particular given string where the size varies for different string.
“abc def
ghi jkl”
Here I want to get the index of the EOL or enter (after def). I tried it using regex but its not working properly. Can anyone please suggest a solution for this.

Is EOL string is repetitive?

No just once. Even if it is repetitive we could store result as a list for further manipulation. But, the basic detection is what I need help with.

can you please share me how did you tried with regex? regex should work…


Also tried ismatches for expression.
And played around with regex like “/r/n” etc.

Try the Regex Pattern “EOL” using ISMatches you will get all the instances. if you get only one instance use string.index(regext(0))


why don’t you split the string on Environment.NewLine and store the result into a string array.
then loop the string array and find the length of each line.

Please follow below steps-

  1. Your string, strInput = “abc def
    ghi jkl”;
  2. Check EOL exists-
    strInput.Contains(“EOL”) or
    strInput.ToUpper.Contains(“EOL”) => If case should not be considered
    The output will be a boolean value, bIsEOLExists
  3. If EOL doesn’t exists, check index of first new line, intIndex
    Output will be integer variable. Check if output > -1 => New line exists.
  4. If newline exists, insert EOL.
    strInput.Insert(intIndex, “EOL”)

Hope this helps.