【问题标题】:Error when splitting string with string用字符串拆分字符串时出错
【发布时间】:2011-07-14 15:58:39
【问题描述】:

如何用字符串拆分字符串?

string PostBuffer = "This Is First----WebKitFormBoundaryBBZbLlWzO0CIcUa6This Is Last"
string[] bufferarray =  PostBuffer.Split("----WebKitFormBoundaryBBZbLlWzO0CIcUa6", StringSplitOptions.None);

我得到并且错误 cannot convert Argument '1' from string to char 并且我得到 Argument '2' cannot convert from system.stringsplitoptions to char。

我做错了什么?

【问题讨论】:

    标签: c# asp.net visual-studio split string-split


    【解决方案1】:
    PostBuffer.Split(new string[] { "----WebKitFormBoundaryBBZbLlWzO0CIcUa6"}, StringSplitOptions.None);
    

    【讨论】:

      【解决方案2】:

      这是因为第一个参数是:

      类型:System.String() 分隔子字符串的字符串数组 在此字符串中,一个不包含分隔符的空数组,或 什么都没有。

      所以你需要这样做:

      string[] bufferarray = 
      PostBuffer.Split(new string[] { "----WebKitFormBoundaryBBZbLlWzO0CIcUa6" }, StringSplitOptions.None);
      

      您可以从the docs阅读更多内容。

      【讨论】:

        【解决方案3】:

        string.Split 没有重载,它接受一个字符串和StringSplitOptions 作为参数。改为这样做:

        string[] bufferarray = 
        PostBuffer.Split(new string[] { "----WebKitFormBoundaryBBZbLlWzO0CIcUa6" }, StringSplitOptions.None);
        

        【讨论】:

          猜你喜欢
          • 2014-01-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-02-26
          • 2014-05-27
          • 1970-01-01
          • 1970-01-01
          • 2015-12-28
          相关资源
          最近更新 更多