将两个类似标识符C#之间的修剪文本

发布于 2025-01-17 15:53:48 字数 467 浏览 2 评论 0原文

我有一个字符串

string myString = "NotNeeded/ThisTextIsNeeded/NotNeeded";

,我只需要“ thisTextisneed ”,而开始和结束标识符是相同的“/” 。我可以使用子字符串,但为此我需要不同的标识符。任何人都可以使用C#中的类似标识符引导我如何做到这一点。

编辑:不一定是“ noted/thisTextisneed/notneded ”。也可以更改它,例如“ abc/thisTextisneed/abc ”或“ aaa/apppp/abc ”。我只需要//之间的任何文本。

谢谢

I have a string

string myString = "NotNeeded/ThisTextIsNeeded/NotNeeded";

I just need "ThisTextIsNeeded" and the starting and ending identifiers are same "/". I can use Substring but for that I will need different identifiers. Can anyone please guide me how to do it using similar identifiers in C#.

Edit: The string cannot be necessarily "NotNeeded/ThisTextIsNeeded/NotNeeded". It can also be changed for example "ABC/ThisTextIsNeeded/ABC" or "AAA/APPPP/ABC". I just need any text that comes in between / and /.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稀香 2025-01-24 15:53:48

1- 您可以使用正则表达式

string regexPattern = @"(?<=\/)(.*?)(?=\/)";
var match = Regex.Match("NotNeeded/ThisTextIsNeeded/NotNeeded", regexPattern);

输出: ThisTextIsNeeded

2- 或者,分割 < code>string 通过使用 "/"

string text = "NotNeeded/ThisTextIsNeeded/NotNeeded";
string[] list = text.Split('/');

输出: list[1] 将是 -> 需要此文本

1- You can use regex

string regexPattern = @"(?<=\/)(.*?)(?=\/)";
var match = Regex.Match("NotNeeded/ThisTextIsNeeded/NotNeeded", regexPattern);

Output: ThisTextIsNeeded

2- Or, Split string by using "/"

string text = "NotNeeded/ThisTextIsNeeded/NotNeeded";
string[] list = text.Split('/');

Output: list[1] will be -> ThisTextIsNeeded

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文