【问题标题】:How to split/extract complex string data c# [duplicate]如何拆分/提取复杂的字符串数据c# [重复]
【发布时间】:2017-08-02 07:40:19
【问题描述】:

在这种情况下,我的字符串中可能包含的数据可能如下所示,但请记住,id 是动态生成的,因此这不是静态的,如果您没有注意到它,可能会超过 2 个。

ing:服务器等等等等,你。 2019,;:10-!gs.csd 1。 id=value,otherid=value,pos=(22,22,33) 2. id=value2, otherid=value2, pos=(2g,2g,f) info other info info info info etc.

编辑:我应该如何从字符串中提取单个值到字符串中,以下不起作用:

String valueString = "csd 1. id=value, otherid=value, pos=(22,22,33) ";

String value = valueString.Substring(valueString.IndexOf("otherid"), valueString.IndexOf(",") - valueString.IndexOf("otherid"));

【问题讨论】:

    标签: c# .net winforms


    【解决方案1】:

    您可以使用子字符串,因为您已经知道何时开始和何时结束搜索。

    string result = x.Substring(x.IndexOf("csd"), (x.IndexOf("info ") - x.IndexOf("csd")));
    

    我从单词“csd”的开头开始搜索,并以单词“info”(带空格)结尾,因为在您的字符串开头还有一个 info 单词。

    结果是:

    "csd 1. id=value, otherid=value, pos=(22,22,33) 2. id=value2, otherid=value2, pos=(24,21,33) "
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      • 1970-01-01
      • 2015-11-20
      • 2012-09-18
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      相关资源
      最近更新 更多