Possible Duplicate:
string split in c#
Hello guys i am getting connected ip address from socket which is looks like this: >> “188.169.28.103:61635” how i can put ip address into one string and port into another?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Personally I’d use
Substring:Mark mentioned using
string.Splitwhich is a good option too – but then you should probably check the number of parts:Or if you’re happy with the port part containing a colon (as my
Substringversion does) then you can use:Another alternative would be to use a regular expression to match the two parts as groups. To be honest I’d say that’s overkill at the moment, but if things became more complicated it may become a more attractive option. (I tend to use simple string operations until things start getting hairy and more “pattern-like”, at which point I break out regular expressions with some trepidation.)