1. Determine whether a character contains a specific character:
Public void FindStringchar (string A, string B)
{
If (A. IndexOf (B)>-1)
{
Console. WriteLine ("exists! ");
}
Else
{
Console. WriteLine ("does not exist! ");
}
}
For example:
String A = "abceFC (";
String B = "x ";
String C = "B ";
2. determine the number of times the substring in the string appears in the main string
Public int FindSubstringCount (string mainString, string subString)
{
String interString = mainString. Replace ("", ""); // remove space
Int count = 0; // counter
For (int I = 0; I <interString. Length-2; I ++)
{
String findString = interString (I, subString. Length );
If (findString = subString)
{
Count ++;
}
} // End
Return count;
} // End FindSubstringCount ()
For example:
MainString = "abc beefff cadde cabb bbace atbba ";
SubString = "bb ";
This program is slightly rewritten to find the location of the same string in the string, and find the characters after the same string,
Or read the output into the array, and so on.
3. Read the substring from a character.
String mainString = "goodpackga <AB> AB ";
String resultString = string. Empty;
Int end = mainString. IndexOf ("<");
RestultString = mainString. Substring (0, end );