locked
Unable to split string based on SOH delimeter RRS feed

  • Question

  • Hi All,

    I am unable to split the below string based on SOH (start of heading) delimiter.
    {SomeText}ETX SOH{SomeText}

    I have tried with below code but no luck.
    var parts = Regex.Split(inputText, @"[\SOH] ");

    Could you please help me in splitting the line.

    Regards,
    Rabindra

    • Changed type BonnieBMVP Friday, November 27, 2015 6:00 AM
    Thursday, November 26, 2015 12:21 PM

Answers

  • Ah, Split works perfectly fine with control characters.

    Assuming that the start of heading character is Unicode char U+0001, you can just specify that using the appropriate escape sequence of \x0001:

    string inputText = "{SomeText}ETX \x0001{SomeText}";
     
    var parts = inputText.Split('\x0001');

    • Marked as answer by BonnieBMVP Friday, November 27, 2015 6:00 AM
    Thursday, November 26, 2015 1:04 PM

All replies

  • Unless the splitting logic needs to be more complex, you could just do this with the string Split method:

    string inputText = "{SomeText}ETX SOH{SomeText}";
     
    var parts = inputText.Split(new string[1] {"SOH"}, StringSplitOptions.None);

    Thursday, November 26, 2015 12:40 PM
  • Hi,

    Thanks for you reply but it did not work. SOH is a special character. It represents Start of Heading. Kindly give me some other way to split the string.

    Thanks,

    Rabindra


    Thursday, November 26, 2015 12:52 PM
  • Ah, Split works perfectly fine with control characters.

    Assuming that the start of heading character is Unicode char U+0001, you can just specify that using the appropriate escape sequence of \x0001:

    string inputText = "{SomeText}ETX \x0001{SomeText}";
     
    var parts = inputText.Split('\x0001');

    • Marked as answer by BonnieBMVP Friday, November 27, 2015 6:00 AM
    Thursday, November 26, 2015 1:04 PM
  • Hi, Thanks a lot. It finally worked.

    Regards,
    Rabindra


    Friday, November 27, 2015 4:41 AM