C# 如果不想读取整个字符串,该怎么办?
如果我有一个数字和符号的组合,我应该怎么做,然后我只想读没有符号的数字。例如,我有这样的号码:C# 如果不想读取整个字符串,该怎么办?,c#,asp.net,int,C#,Asp.net,Int,如果我有一个数字和符号的组合,我应该怎么做,然后我只想读没有符号的数字。例如,我有这样的号码: 626120524133452_1400231752 通过使用C#,是否有任何可能的方法不读取整个字符串,我只想读取下划线前的数字 626120524133452 >> like this 我该怎么办?请给我一些想法,伙计们。提前感谢。您可以使用以下方法: string s = "626120524133452_1400231752"; int index = s.IndexOf('_
626120524133452_1400231752
通过使用C#,是否有任何可能的方法不读取整个字符串,我只想读取下划线前的数字
626120524133452 >> like this
我该怎么办?请给我一些想法,伙计们。提前感谢。您可以使用以下方法:
string s = "626120524133452_1400231752";
int index = s.IndexOf('_');
string result = s.Substring(0, index);
Console.WriteLine(result); // Print 626120524133452
您可以使用以下方法:
string s = "626120524133452_1400231752";
int index = s.IndexOf('_');
string result = s.Substring(0, index);
Console.WriteLine(result); // Print 626120524133452
字符串只是可以查询的字符序列:
var input = "626120524133452_1400231752";
var firstNumber = new string(input.TakeWhile(Char.IsDigit).ToArray());
字符串只是可以查询的字符序列:
var input = "626120524133452_1400231752";
var firstNumber = new string(input.TakeWhile(Char.IsDigit).ToArray());
如果确定u符号将用作分隔符,则可以拆分字符串。 这是一个如何操作的演示(split中也有几个选项,请尝试使用它们)
如果确定u符号将用作分隔符,则可以拆分字符串。 这是一个如何操作的演示(split中也有几个选项,请尝试使用它们)
string.Split不接受字符串、传递字符、str.Split(“”);string.Split不接受字符串、传递字符、str.Split(“”);