将字符串拆分为字符串数组。 [英] Splitting an string into a string array.

查看:144
本文介绍了将字符串拆分为字符串数组。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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


这篇关于将字符串拆分为字符串数组。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆