开发者

How to extract text before a period from a string in C#?

开发者 https://www.devze.com 2022-12-13 13:20 出处:网络
Say I have a string whose text is something like, \"mohdibrahim.tas开发者_StackOverflowal\". I want to extract \"mohdibrahim\" from this string.

Say I have a string whose text is something like, "mohdibrahim.tas开发者_StackOverflowal". I want to extract "mohdibrahim" from this string.

I've tried this code:

string updateUser1 = user1.Trim(); 

Is this the correct approach, or is there another technique I should be using?


OK, lets assume i think i know what you want.

Try

string user = user1.Split('.')[0];

This will split the string on the '.' and return the last part.


This will return everything before the period(".")

string updateUser1 = user1.Substring(0,user1.IndexOf("."));


try

string updateUser1 = user1.Substr(user1.IndexOf(".")+1);

I haven't tested it though.

0

精彩评论

暂无评论...
验证码 换一张
取 消