2016-07-04 8 views
0

String.Splitを処理するときに返されるエントリの数に上限があるかどうかは知りませんか?私は "1,1,1,1,1,1,1、..."という文字列を600個のエントリで持っていますが、返される配列の201個のエントリしか返しません。ありがとう!文字列分割の上限は返されますか?

EDIT: これはコードの1行だけです。実行時にウォッチャを開いて、文字列にまだ600カンマ/エントリがあることを確認しました。

結果のsplitLine配列には201個のエントリしか含まれていません。

EDIT 2: 私はばかだとカウントすることはできませんが、文字列にカンマとスペースを含む601文字があることを理解できませんでした。みんな、ありがとう!

+0

私は問題なく2245のエントリを処理しました。コードを表示できますか?私の推測は、そこに何かがあることです。 – kemiller2002

+2

コードで問題を投稿してください。問題の内容を推測して詳細を確認せずに確認してください。 – Blorgbeard

答えて

3

String.Splitメソッドのソースコードintを見ると、は、分割文字列には制限がありません。

 [ComVisible(false)] 
     internal String[] SplitInternal(char[] separator, int count, StringSplitOptions options) 
     { 
     if (count < 0) 
      throw new ArgumentOutOfRangeException("count", 
       Environment.GetResourceString("ArgumentOutOfRange_NegativeCount")); 

     if (options < StringSplitOptions.None || options > StringSplitOptions.RemoveEmptyEntries) 
      throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", options)); 
     Contract.Ensures(Contract.Result<String[]>() != null); 
     Contract.EndContractBlock(); 

     bool omitEmptyEntries = (options == StringSplitOptions.RemoveEmptyEntries); 

     if ((count == 0) || (omitEmptyEntries && this.Length == 0)) 
     {   
      return new String[0]; 
     } 

     int[] sepList = new int[Length];    
     int numReplaces = MakeSeparatorList(separator, ref sepList);    

     //Handle the special case of no replaces and special count. 
     if (0 == numReplaces || count == 1) { 
      String[] stringArray = new String[1]; 
      stringArray[0] = this; 
      return stringArray; 
     }    

     if(omitEmptyEntries) 
     { 
      return InternalSplitOmitEmptyEntries(sepList, null, numReplaces, count); 
     } 
     else 
     { 
      return InternalSplitKeepEmptyEntries(sepList, null, numReplaces, count); 
     }    
    } 

参考:あなたがここに見ることができるようにhttp://referencesource.microsoft.com/#mscorlib/system/string.cs,baabf9ec3768812a,references

1

、分割方法は、600部を返します。

using System; 
using System.Text; 

public class Program 
{ 
    public static void Main() 
    { 
     var baseString = "1,"; 
     var builder = new StringBuilder(); 

     for(var i=0;i<599;i++) 
     { 
      builder.Append(baseString); 
     } 
     builder.Append("1"); 

     var result = builder.ToString().Split(','); 

     Console.WriteLine("Number of parts:{0}",result.Length); 
    } 
} 

https://dotnetfiddle.net/oDosIp

関連する問題