字符串分割求助。
本帖最后由 小栗子 于 2022-8-12 11:46 编辑如何获取红框中的数值
以下是返回的字符串实际值
"EA" & vbCrLf & "DATE 22/08/12" & vbCrLf & "TIME 11:45:57.300 " & vbCrLf & "E 0301 ??C +99999999E-01" & vbCrLf & "E 0302 ??C +99999999E-01" & vbCrLf & "E 0303 ??C +99999999E-01" & vbCrLf & "E 0304 ??C +99999999E-01" & vbCrLf & "E 0305 ??C +99999999E-01" & vbCrLf & "E 0306 ??C +99999999E-01" & vbCrLf & "E 0307 ??C +99999999E-01" & vbCrLf & "E 0308 ??C +99999999E-01" & vbCrLf & "E 0309 ??C +99999999E-01" & vbCrLf & "E 0310 ??C +99999999E-01" & vbCrLf & "O 0401 ??C -99999999E-01" & vbCrLf & "N 0402 V +00000000E-04" & vbCrLf & "N 0403 V +00000000E-04" & vbCrLf & "N 0404 V +00000001E-04" & vbCrLf & "N 0405 V +00000001E-04" & vbCrLf & "N 0406 V +00000001E-04" & vbCrLf & "N 0407 V +00000001E-04" & vbCrLf & "N 0408 V +00000001E-04" & vbCrLf & "N 0409 V +00000001E-04" & vbCrLf & "N 0410 V +00000001E-04" & vbCrLf & "N 0501 ??C -00000611E-01" & vbCrLf & "N 0502 V +00000000E-04" & vbCrLf & "N 0503 V +00000000E-04" & vbCrLf & "N 0504 V +00000000E-04" & vbCrLf & "N 0505 V +00000000E-04" & vbCrLf & "N 0506 V +00000000E-04" & vbCrLf & "N 0507 V +00000001E-04" & vbCrLf & "N 0508 V +00000001E-04" & vbCrLf & "EN" & vbCrLf
写个正则表达式来匹配
import re
value = '"EA" & vbCrLf & "DATE 22/08/12" & vbCrLf & "TIME 11:45:57.300 " & vbCrLf & "E 0301 ??C +99999999E-01" & vbCrLf & "E 0302 ??C +99999999E-01" & vbCrLf & "E 0303 ??C +99999999E-01" & vbCrLf & "E 0304 ??C +99999999E-01" & vbCrLf & "E 0305 ??C +99999999E-01" & vbCrLf & "E 0306 ??C +99999999E-01" & vbCrLf & "E 0307 ??C +99999999E-01" & vbCrLf & "E 0308 ??C +99999999E-01" & vbCrLf & "E 0309 ??C +99999999E-01" & vbCrLf & "E 0310 ??C +99999999E-01" & vbCrLf & "O 0401 ??C -99999999E-01" & vbCrLf & "N 0402 V +00000000E-04" & vbCrLf & "N 0403 V +00000000E-04" & vbCrLf & "N 0404 V +00000001E-04" & vbCrLf & "N 0405 V +00000001E-04" & vbCrLf & "N 0406 V +00000001E-04" & vbCrLf & "N 0407 V +00000001E-04" & vbCrLf & "N 0408 V +00000001E-04" & vbCrLf & "N 0409 V +00000001E-04" & vbCrLf & "N 0410 V +00000001E-04" & vbCrLf & "N 0501 ??C -00000611E-01" & vbCrLf & "N 0502 V +00000000E-04" & vbCrLf & "N 0503 V +00000000E-04" & vbCrLf & "N 0504 V +00000000E-04" & vbCrLf & "N 0505 V +00000000E-04" & vbCrLf & "N 0506 V +00000000E-04" & vbCrLf & "N 0507 V +00000001E-04" & vbCrLf & "N 0508 V +00000001E-04" & vbCrLf & "EN" & vbCrLf'
valueList = re.findall("[+-]+E-+",value)
print(valueList) 临时号 发表于 2022-8-12 11:57
写个正则表达式来匹配
大佬用C#怎么解析啊? 小栗子 发表于 2022-8-12 12:31
大佬用C#怎么解析啊?
一样,很多语言都支持
using System;
using System.Text.RegularExpressions;
namespace RegExApplication
{
class Program
{
static void Main(string[] args)
{
string value = "\"EA\" & vbCrLf & \"DATE 22/08/12\" & vbCrLf & \"TIME 11:45:57.300 \" & vbCrLf & \"E 0301 ??C +99999999E-01\" & vbCrLf & \"E 0302 ??C +99999999E-01\" & vbCrLf & \"E 0303 ??C +99999999E-01\" & vbCrLf & \"E 0304 ??C +99999999E-01\" & vbCrLf & \"E 0305 ??C +99999999E-01\" & vbCrLf & \"E 0306 ??C +99999999E-01\" & vbCrLf & \"E 0307 ??C +99999999E-01\" & vbCrLf & \"E 0308 ??C +99999999E-01\" & vbCrLf & \"E 0309 ??C +99999999E-01\" & vbCrLf & \"E 0310 ??C +99999999E-01\" & vbCrLf & \"O 0401 ??C -99999999E-01\" & vbCrLf & \"N 0402 V +00000000E-04\" & vbCrLf & \"N 0403 V +00000000E-04\" & vbCrLf & \"N 0404 V +00000001E-04\" & vbCrLf & \"N 0405 V +00000001E-04\" & vbCrLf & \"N 0406 V +00000001E-04\" & vbCrLf & \"N 0407 V +00000001E-04\" & vbCrLf & \"N 0408 V +00000001E-04\" & vbCrLf & \"N 0409 V +00000001E-04\" & vbCrLf & \"N 0410 V +00000001E-04\" & vbCrLf & \"N 0501 ??C -00000611E-01\" & vbCrLf & \"N 0502 V +00000000E-04\" & vbCrLf & \"N 0503 V +00000000E-04\" & vbCrLf & \"N 0504 V +00000000E-04\" & vbCrLf & \"N 0505 V +00000000E-04\" & vbCrLf & \"N 0506 V +00000000E-04\" & vbCrLf & \"N 0507 V +00000001E-04\" & vbCrLf & \"N 0508 V +00000001E-04\" & vbCrLf & \"EN\" & vbCrLf";
MatchCollection mc = Regex.Matches(value, "[+-]+E-+");
foreach (Match m in mc)
{
Console.WriteLine(m);
}
}
}
} 临时号 发表于 2022-8-12 12:47
一样,很多语言都支持
嗯嗯 已经解决的非常感谢{:5_109:}
页:
[1]