delphi '{''NAME'':''测试2'',''DEPCODE'':''NULL'',''ID'':''0000001'',''USER_TYPE'':''1@本行员工''}' 提取元素
时间: 2023-12-21 18:27:44 浏览: 27
要提取元素,可以使用正则表达式来匹配需要的部分。以下是一个示例代码:
```delphi
uses
RegularExpressions;
var
input: string;
pattern: string;
match: TMatch;
begin
input := '{''NAME'':''测试2'',''DEPCODE'':''NULL'',''ID'':''0000001'',''USER_TYPE'':''1@本行员工''}';
pattern := '''ID'':''(.*?)'''; // 匹配 ID 的值
match := TRegEx.Match(input, pattern);
if match.Success then
Writeln(match.Groups[1].Value); // 输出匹配到的值
end.
```
输出结果为:`0000001`
相关问题
'{''NAME'':''测试2'',''DEPCODE'':''NULL'',''ID'':''0000001'',''USER_TYPE'':''1@本行员工''}' 分别提取name、DEPCODE、ID、USER_TYPE的值 delphi
您可以使用 Delphi 中的 JSON 解析库来解析该 JSON 字符串,然后提取相应的值。以下是示例代码:
```delphi
uses
System.JSON;
var
jsonObj: TJSONObject;
name, depcode, id, user_type: string;
begin
jsonObj := TJSONObject.ParseJSONValue('{''NAME'':''测试2'',''DEPCODE'':''NULL'',''ID'':''0000001'',''USER_TYPE'':''1@本行员工''}') as TJSONObject;
try
name := jsonObj.GetValue('NAME').Value;
depcode := jsonObj.GetValue('DEPCODE').Value;
id := jsonObj.GetValue('ID').Value;
user_type := jsonObj.GetValue('USER_TYPE').Value;
finally
jsonObj.Free;
end;
end;
```
delphi 提取字符串'{''NAME'':''测试2'',''DEPCODE'':''NULL'',''ID'':''0000001'',''USER_TYPE'':''1@本行员工''}' 分别提取name、DEPCODE、ID、USER_TYPE的值
可以使用正则表达式来提取字符串中的值。以下是 Delphi 中提取字符串的示例代码:
```delphi
uses
RegularExpressions;
function ExtractValue(const input, key: string): string;
var
regex: TRegEx;
match: TMatch;
begin
regex := TRegEx.Create('(?<=' + key + ''':''\s*'')[^'']+(?='')');
match := regex.Match(input);
if match.Success then
Result := match.Value
else
Result := '';
end;
var
input: string;
name, depcode, id, user_type: string;
begin
input := '{''NAME'':''测试2'',''DEPCODE'':''NULL'',''ID'':''0000001'',''USER_TYPE'':''1@本行员工''}';
name := ExtractValue(input, 'NAME');
depcode := ExtractValue(input, 'DEPCODE');
id := ExtractValue(input, 'ID');
user_type := ExtractValue(input, 'USER_TYPE');
end.
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)