C#StringSubstring截取字符串和截取指定字符间的字符
`
//获取扫描枪barcode
if (message2 != "" && message2.Length < 22 && (!message2.Contains("WG"))) {
//截取字段(产品族、壳体、控制器型号、极数)
string family = message2.Substring(14, 2);
string housing = message2.Substring(16, 2);
string controller_type = message2.Substring(18, 2);
string pole = message2.Substring(20, 1);
}
`
二、提取固定字符间的字符
`
/// <summary> /// 提取打印内容
/// </summary>
/// <param name="teshubeizhu"></param>
private void GetPrintContent(string teshubeizhu )
{
//获取#号的数量
int count = GetCharCount(teshubeizhu);
if (teshubeizhu != "" && count == 2)
{
//提取打印内容
printContent = Regex.Matches(teshubeizhu, "(?<=beginstr).*?(?=endstr)").ToString();
}
}
/// <summary>
/// 计算字符串个数
/// </summary>
/// <param name="InputValue"></param>
/// <returns></returns>
private int GetCharCount(string InputValue)
{
return InputValue.Split("#").Length - 1;
}
`
以上是 C#StringSubstring截取字符串和截取指定字符间的字符 的全部内容, 来源链接: utcz.com/z/515137.html