弦:
https://company.zendesk.com/api/v2/tickets/33126.json
番号 33126 が必要です。
この数を抽出する最適な方法は何ですか?
弦:
https://company.zendesk.com/api/v2/tickets/33126.json
番号 33126 が必要です。
この数を抽出する最適な方法は何ですか?
これはパス/URL であるため、次を使用します Path.GetFileNameWithoutExtension
。
string name = Path.GetFileNameWithoutExtension(path);
が望ましいですが、代わりにクラスPath
を使用する場合は、Uri
これも使用できます。
Uri uri = new Uri("https://company.zendesk.com/api/v2/tickets/33126.json");
string lastSegment = uri.Segments.Last();
string name = lastSegment.Substring(0, lastSegment.IndexOf('.'));
これは正規表現の仕事のように見えます。
Regex regex = new Regex(@"https://company.zendesk.com/api/v2/tickets/(\d+).json");
Match match = regex.Match("https://company.zendesk.com/api/v2/tickets/33126.json");
foreach(Group group in match.Groups)
{
Console.WriteLine(group.Value);
}