c# - Detecting part of string and using part of it in a variable -
i have tcp server setup receives strings of text clients.
data = new byte[1024]; recv = client.receive(data); string recvconv = encoding.ascii.getstring(data, 0, recv);
i can detect string , example:
if (recvconv == "l") { console.writeline(encoding.ascii.getstring(data, 0, recv)); console.writeline("l printed..."); }
however need detect part of string. example, "name:programmer". need able detect "name:" part, , assign "programmer" part of string variable.
i not sure how this. have tried using substring, , other string techniques have no idea doing.
you can use string.split method.
https://msdn.microsoft.com/en-us/library/system.string.split%28v=vs.110%29.aspx
data = new byte[1024]; recv = client.receive(data); string recvconv = encoding.ascii.getstring(data, 0, recv); string[] results = recvconv.split(':'); foreach (string result in results) { console.writeline(result); }
Comments
Post a Comment