首页 > 解决方案 > 从 C# 中的 url 字符串中获取数字部分

问题描述

我有一个如下所示的 URL 字符串:

https://example.com/app/1095600/example2234

我只想得到“ 1095600

这个数字是可变的,可以是三位数或更多位数。

标签: c#stringurl

解决方案


如果数字始终位于同一位置(在 之后https://example.com/app/),您可以用斜杠 ( ) 字符分割字符串/并提取它:

string input = "https://example.com/app/1095600/example2234";
string result = input.Split("/")[4];

推荐阅读