从数组中检索数据
本文关键字:数据 检索 数组 | 更新日期: 2023-09-27 17:55:24
我有byte[] array Q
包含一些数据。要将数组转换为字符串,我正在使用result=System.Text.Encoding.ASCII.GetString(Q);
结果类似于JOBID: 196035002'n
.我只需要它的整数部分。有没有办法只获取196035002
int
值而不转换为字符串并拆分为另一个数组?
我认为你说的语言是C#。您需要做的是:
char[] delimiterChars = { ':' };
string[] words = result.Split(delimiterChars);
foreach (string s in words)
{
System.Console.WriteLine(s);
}
如果您不想使用像 Split
这样的函数,那么您可以尝试使用此正则表达式来获得所需的输出。
String inputString = "JOBID: 196035002'n";
Int32 result = Convert.ToInt32(Regex.Match(inputString, @"'d+").Value);
正则表达式的命名空间:using System.Text.RegularExpressions;