开发者

Substring in asp.net

开发者 https://www.devze.com 2023-01-18 06:27 出处:网络
\"01 ABC\" \"123 DEF\" How can I开发者_如何学编程 get the value of \"01\" and \"123\" in asp.net?

"01 ABC"

"123 DEF"

How can I开发者_如何学编程 get the value of "01" and "123" in asp.net?

I have tried the following code:

Dim ddlSession As String = "01 ABC"
Dim getSpaceIndex As Integer = ddlSession.IndexOf(" ")
Dim getSessionCode As String = ddlSession.Remove(getSpaceIndex)

but the getSpaceIndex will keep return -1 to me...


It depends on what exactly you want.

If you want the substring until the space character, you can use:

string ddlSessionText = "01 ABC";
string sessionCode = ddlSessionText.Substring(0, ddlSessionText.IndexOf(' '));


string.Substring(0, string.IndexOf(" "));


You can use split.

Assuming you are using C# in your ASP.NET page:

string s = "01 ABC";
s.split(' ')[0]; // will give you 01
s = "123 DEF";
s.split(' ')[0]; // will give you 123
0

精彩评论

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