C#相当于C++;std::字符串查找
我正在寻找C#相当于C++;std::字符串查找,c#,c++,linq,C#,C++,Linq,我正在寻找c++std::string在c# 因此,在c++中,您可以: string s, nucleo = "ATGC"; s = "TCCCTCCATGCAG"; for (int i = 0; i < (int) s.length(); i++) { v = append(v, nucleo.find(s[i])); ... } 字符串s,nucleo=“ATGC”; s=“TCCCATGCAG”; 对于(int i=0;i
c++
std::string在c#
因此,在c++
中,您可以:
string s, nucleo = "ATGC";
s = "TCCCTCCATGCAG";
for (int i = 0; i < (int) s.length(); i++) {
v = append(v, nucleo.find(s[i]));
...
}
字符串s,nucleo=“ATGC”;
s=“TCCCATGCAG”;
对于(int i=0;i<(int)s.length();i++){
v=追加(v,核子查找(s[i]);
...
}
在linq或loop中nucleo.find会是什么样子
我现在有
int? found = s.find(nucleo);
public static int? find(this string source, string what)
{
if (source == null) throw new ArgumentNullException("source");
if (what == null) throw new ArgumentNullException("what");
if (source.Length == 0) return null;
if (what.Length == 0) return 0;
for (int i = 0; i < source.Length; i++)
{
if (source.IndexOf(source[i]) == -1) return i;
}
return null;
}
int?found=s.find(核仁);
公共静态int?查找(此字符串源,字符串内容)
{
如果(source==null)抛出新的ArgumentNullException(“source”);
如果(what==null)抛出新的ArgumentNullException(“what”);
if(source.Length==0)返回null;
如果(what.Length==0)返回0;
for(int i=0;i
或者您可以使用Contains
string s1 = "The quick brown fox jumps over the lazy dog";
string s2 = "fox";
bool b;
b = s1.Contains(s2);
Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);
或者您可以使用Contains
string s1 = "The quick brown fox jumps over the lazy dog";
string s2 = "fox";
bool b;
b = s1.Contains(s2);
Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);
或者您可以使用Contains
string s1 = "The quick brown fox jumps over the lazy dog";
string s2 = "fox";
bool b;
b = s1.Contains(s2);
Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);
或者您可以使用Contains
string s1 = "The quick brown fox jumps over the lazy dog";
string s2 = "fox";
bool b;
b = s1.Contains(s2);
Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);
你的C#代码毫无意义——看起来你自己在实现String.IndexOf
,而你只需要直接调用它
C++的std::string::find
返回第一个匹配的第一个字符的位置(即字符索引)(在可选的起始位置参数之后),这与.NET的string.IndexOf
方法的行为相同。唯一的区别是find
在不匹配时返回npos
,但IndexOf
返回-1
只需执行此操作(如果要使用null
作为不匹配的值):
你的C#代码毫无意义——看起来你自己在实现String.IndexOf
,而你只需要直接调用它
C++的std::string::find
返回第一个匹配的第一个字符的位置(即字符索引)(在可选的起始位置参数之后),这与.NET的string.IndexOf
方法的行为相同。唯一的区别是find
在不匹配时返回npos
,但IndexOf
返回-1
只需执行此操作(如果要使用null
作为不匹配的值):
你的C#代码毫无意义——看起来你自己在实现String.IndexOf
,而你只需要直接调用它
C++的std::string::find
返回第一个匹配的第一个字符的位置(即字符索引)(在可选的起始位置参数之后),这与.NET的string.IndexOf
方法的行为相同。唯一的区别是find
在不匹配时返回npos
,但IndexOf
返回-1
只需执行此操作(如果要使用null
作为不匹配的值):
你的C#代码毫无意义——看起来你自己在实现String.IndexOf
,而你只需要直接调用它
C++的std::string::find
返回第一个匹配的第一个字符的位置(即字符索引)(在可选的起始位置参数之后),这与.NET的string.IndexOf
方法的行为相同。唯一的区别是find
在不匹配时返回npos
,但IndexOf
返回-1
只需执行此操作(如果要使用null
作为不匹配的值):