gpt4 book ai didi

c# - 从字符串行解析 GUID

转载 作者:行者123 更新时间:2023-11-30 13:27:31 26 4
gpt4 key购买 nike

我有不同的选项如何将我的 GUID 存储为字符串行。

1. Accessibility|5102d73a-1b0b-4461-93cd-0c024738c19e
2. 5102d73a-1b0b-4461-93cd-0c024738c19e;#5102d73a-1b0b-4461-93cd-0c024733d52d
3. |;#5102d73a-1b0b-4461-93cd-0c024738c19e;#SharePointTag|5102d73a-1b0b-4461-93cd-0c024733d52d
3. Business pages|;#5102d73a-1b0b-4461-93cd-0c024738cz13;#SharePointTag|5102d73a-1b0b-4461-93cd-0c024733d52d

你们能帮我想想我如何解析这个标签并最终获得 Guids 类型列表吗?也许正则表达式在这种情况下会有所帮助?

最佳答案

看起来您正在玩托管元数据、术语库 ID 和术语集 ID :)

只需使用常规正则表达式(下面的“p”变量):

string c1 = "Accessibility|5102d73a-1b0b-4461-93cd-0c024738c19e";
string c2 = "5102d73a-1b0b-4461-93cd-0c024738c19e;#5102d73a-1b0b-4461-93cd-0c024733d52d";
string c3 = "|;#5102d73a-1b0b-4461-93cd-0c024738c19e;#SharePointTag|5102d73a-1b0b-4461-93cd-0c024733d52d";
string c4 = "Business pages|;#5102d73a-1b0b-4461-93cd-0c024738cz13;#SharePointTag|5102d73a-1b0b-4461-93cd-0c024733d52d";
string p = @"([a-zA-Z0-9]{8}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{4}[-][a-zA-Z0-9]{12})";

MatchCollection mc;

Console.WriteLine("#1");
mc = Regex.Matches(c1, p);
foreach (var id in mc)
Console.WriteLine(id);

Console.WriteLine("#2");
mc = Regex.Matches(c2, p);
foreach (var id in mc)
Console.WriteLine(id);

Console.WriteLine("#3");
mc = Regex.Matches(c3, p);
foreach (var id in mc)
Console.WriteLine(id);

Console.WriteLine("#4");
mc = Regex.Matches(c4, p);
foreach (var id in mc)
Console.WriteLine(id);

输出:

#1
5102d73a-1b0b-4461-93cd-0c024738c19e
#2
5102d73a-1b0b-4461-93cd-0c024738c19e
5102d73a-1b0b-4461-93cd-0c024733d52d
#3
5102d73a-1b0b-4461-93cd-0c024738c19e
5102d73a-1b0b-4461-93cd-0c024733d52d
#4
5102d73a-1b0b-4461-93cd-0c024738cz13
5102d73a-1b0b-4461-93cd-0c024733d52d
Press any key to continue...

关于c# - 从字符串行解析 GUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10602827/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com