public int LastlndexOf(string value)
public int LastlndexOf(string value, StringComparison comparisonType)
, value, . StringComparison, . , -1.
String : IndexOf Any () LastlndexOf Any (). , . .
public int IndexOfAny(char[] anyOf) public int LastlndexOfAny(char[] anyOf)
IndexOf Any () anyOf, , LastlndexOfAny () anyOf, . , -1. , .
, . StartsWith () EndsWith (). .
public bool StartsWith(string value) public bool EndsWith(string value)
StartsWith () true, , value. EndsWith () true, , value. false.
. , StringComparison.
public bool StartsWith(string value, StringComparison comparisonType) public bool EndsWith(string value, StringComparison comparisonType)
, . .
.
// .
Using System;
class StringSearchDemo { static void Main() {
string str = "C# ."; int idx;
Console.WriteLine(" str: " + str); idx = str.IndexOf('o');
Console.WriteLine(" 'o': " + idx); idx = str.LastlndexOf('');
Console.WriteLine(" 'o': " + idx); idx = str.IndexOf("", StringComparison.Ordinal);
|
|
Console.WriteLine(" \"\": " + idx); idx = str.LastlndexOf("", StringComparison.Ordinal);
Console.WriteLine(" \"\": " + idx);
char[] chrs = { 1 a', '6', 1 ' };
idx = str.IndexOfAny(chrs);
Console.WriteLine(" " +
" '1, '' '': " + idx);
if(str.StartsWith("C# ", StringComparison.Ordinal))
Console.WriteLine(" str \"C# \"");
if(str.EndsWith(".", StringComparison.Ordinal))
Console.WriteLine(" str \".\"");
}
}