我在C#中执行sql查询时遇到问题。当字符串在IN CLAUSE中包含超过1000个enteries时,sql查询会抛出错误。该字符串有超过1000个子字符串,每个子字符串由'','分隔。 我想将字符串拆分成字符串数组,每个字符串包含999个字符串,分别用'',''。 或 如何在字符串中找到'',''的第n个出现。
解决方案看看String.Split string foo = a,b,c; string [] foos = foo.Split( new char [] {' ,'}); foreach ( var item in foos) { Console.WriteLine(item); }
你可以在C#中快速完成这些。 只需使用字符串.split 功能。 这样的东西可行 - strArry = myString.split(@,) ;
在C#中,只需使用.Split string STR = abc,def,ghi,jkl, MNO,PQR; string [] phrase = STR.Split(' ); string nthPhrase = phrase [n];
或者,您可以使用RegEx获取数字如下
字符串 s = abc,def,ghi,jkl,mno,pqr; int n = 3 ; int j = -1; MatchCollection myMatches = Regex.Matches(s, ,); 如果(myMatches.Count > = n-1) {j = myMatches [n - 1 ]。索引; }希望有所帮助,如果它确实标记为answe / upvote。 Milind
I am facing a problem while executing a sql query in C#.The sql query throws an error when the string contains more than 1000 enteries in the IN CLAUSE .The string has more than 1000 substrings each seperated by '',''. I want to split the string into string array each containing 999 strings seperated by '',''. or How can i find the nth occurence of '','' in a string.
解决方案 Take a look at String.Split string foo = "a,b,c"; string [] foos = foo.Split(new char [] {','}); foreach(var item in foos) { Console.WriteLine(item); }You can do these very quickly in C#. Just use the string.split function. Something like this would work - strArry = myString.split(@",");In C#, simply use .Split string STR = "abc,def,ghi,jkl,mno,pqr"; string[] phrases = STR.Split(','); string nthPhrase = phrases[n];Alternatively, you can use RegEx to get the number as below
String s = "abc,def,ghi,jkl,mno,pqr"; int n = 3; int j=-1; MatchCollection myMatches = Regex.Matches(s, ","); if (myMatches.Count >= n-1 ) { j = myMatches[n - 1].Index; }Hope that helps, If it does mark it as answe/upvote. Milind
更多推荐
将字符串拆分为字符串数组。
发布评论