本文整理汇总了C#中System.Text.StringBuilder.Substring方法的典型用法代码示例。如果您正苦于以下问题:C# System.Text.StringBuilder.Substring方法的具体用法?C# System.Text.StringBuilder.Substring怎么用?C# System.Text.StringBuilder.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.StringBuilder
的用法示例。
在下文中一共展示了System.Text.StringBuilder.Substring方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: splitOptions
/// <summary> Split up a string containing options into an array of strings,
/// one for each option.
///
/// </summary>
/// <param name="optionString">the string containing the options
/// </param>
/// <returns> the array of options
/// </returns>
public static System.String[] splitOptions(System.String quotedOptionString)
{
FastVector optionsVec = new FastVector();
System.String str = new System.Text.StringBuilder(quotedOptionString).ToString();
int i;
while (true)
{
//trimLeft
i = 0;
while ((i < str.Length) && (System.Char.IsWhiteSpace(str[i])))
i++;
str = str.Substring(i);
//stop when str is empty
if (str.Length == 0)
break;
//if str start with a double quote
if (str[0] == '"')
{
//find the first not anti-slached double quote
i = 1;
while (i < str.Length)
{
if (str[i] == str[0])
break;
if (str[i] == '\\')
{
i += 1;
if (i >= str.Length)
throw new System.Exception("String should not finish with \\");
if (str[i] != '\\' && str[i] != '"')
throw new System.Exception("Unknow character \\" + str[i]);
}
i += 1;
}
if (i >= str.Length)
throw new System.Exception("Quote parse error.");
//add the founded string to the option vector (without quotes)
System.String optStr = str.Substring(1, (i) - (1));
optStr = unbackQuoteChars(optStr);
optionsVec.addElement(optStr);
str = str.Substring(i + 1);
}
else
{
//find first whiteSpace
i = 0;
while ((i < str.Length) && (!System.Char.IsWhiteSpace(str[i])))
i++;
//add the founded string to the option vector
System.String optStr = str.Substring(0, (i) - (0));
optionsVec.addElement(optStr);
str = str.Substring(i);
}
}
//convert optionsVec to an array of String
System.String[] options = new System.String[optionsVec.size()];
for (i = 0; i < optionsVec.size(); i++)
{
options[i] = ((System.String) optionsVec.elementAt(i));
}
return options;
}