Skip to main content
edited tags
Link
Source Link

How to read in "\r\n" as a string? trying to split data from an incoming message

I am having an issue trying to receive a string that I need to split as one part of the string has a name and the other part of the string has a location. although I am unsure how to split this data, as when it is received, it should come back as:

"POST /JACK\r\n\r\nis at this building\r\n"

name part is "POST /JACK\r\n\r\n".

location part is "is at this building\r\n".

The code I use to read this incoming message is:

line = sr.ReadLine();

The message is sent through a connected socket to me by an address and port. But when I receive this message, line is returned as: "POST /JACKis at this building"

I did try and use this code before:

            var str = line;
            var Sorted = str.Replace("\\r\\n", System.Environment.NewLine);
            string[] splitted = Sorted.Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

Which basically is meant to look for lines in the string so it can split and sort it but from the looks of it, I cannot use it if I am not getting the "\r\n" from the message, which means I cannot split it.

How would I split the information from the message provided that the message is delivered as: "POST /JACKis at this building" delivered to me?