从开头修剪字符串到子字符串c#

发布于 2024-12-22 02:58:06 字数 434 浏览 1 评论 0原文

我在切断绳子时遇到了麻烦。我有一个接收传入数据的 Windows 窗体应用程序。到目前为止我找到的例子都是使用char来定位的。我需要让它搜索整个 "*S" 而不仅仅是其中的一个字符。

我确实找到了一种方法来获取刺痛的索引,并从该点修剪到末尾(sting.remove)。我的问题是我需要修剪开头。所以修剪索引方法可以工作,但我还没有找到如何做到这一点。

我拥有的是一堆数据,例如

"ok \r\n *S 38773 get 3042"

我需要做的是找到 *S 并删除从开头到 *S 的所有内容。因为返回并不总是相同,所以我无法使用替换或删除方法。我无法预测 *S 之前会发生什么,其余数据是动态的。

任何关于如何从本质上修剪“*S”开始的例子都会很棒。谢谢。

I am having trouble cutting down my string. I have a windows form application that receives incoming data. So far the examples I have found all use char to locate. I need to have it search for the entire "*S" and not just one character of it.

I did find a way to get the index of the sting and trim from that point to the end (sting.remove). My problem is i need to trim the beginning. so a trim to index method would work but I haven't found how to do that.

What i have is a bunch of data like

"ok \r\n *S 38773 get 3042"

What I need to do is locate the *S and remove everything from the beginning to the *S. Because the return is not always the same I cant use replace or remove methods. I cant predict what will come before the *S and the remaining data is dynamic.

Any examples on how to essentially trim start to the "*S" would be wonderful. Thank you.

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

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

发布评论

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

评论(2

剩一世无双 2024-12-29 02:58:06
s = s.Substring(s.IndexOf("*S"));
s = s.Substring(s.IndexOf("*S"));
冬天的雪花 2024-12-29 02:58:06
string huh = "ok \r\n *S 38773 get 3042";
string trimmed = huh.Substring(huh.IndexOf("*S"));
string huh = "ok \r\n *S 38773 get 3042";
string trimmed = huh.Substring(huh.IndexOf("*S"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文