Search code examples
c#textboxdelimiterstring-length

Get length of Textbox before and after delimiter?


I have a textbox that will always have a delimiter in between two words such as Houston|Texas

How do I get the length of the text before, and the length of the text after the '|' delimiter into two separate integers?


Solution

  • Try this:

    string strTest = "Houston|Texas";
    string[] strArr = strTest.Split('|');
    
    int intFirst = strArr[0].Length; //Will result to 7
    int intSecond = strArr[1].Length; //Will result to 5