自然语言:
执行效果:
/// <summary>
/// 把字符串中的所有词找出来,返回一个单词列表
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
/// 创建时间: 2022-08-11 最后一次修改时间:2022-08-11
public static StringList_ _Syntax_字符串_To_词汇列表(this string sText)
{
StringList_ slResult = new StringList_();
StringBuilder sb = new StringBuilder(50);
foreach (char ch in sText)
{
if (ch._IsPunctuation() || ch._IsUnPrintable() || ch._IsControl() || ch._IsWhiteSpace() || ch._IsSeparator() || ch._IsOperationalCharacter())
{
if (sb.Length > 0)
{
slResult.Add(sb.ToString());
sb.Clear();
}
}
else
{
sb.Append(ch);
}
}
return slResult;
}
/// <summary>
/// abstract,assert ,boolean ,break => {"abstract","assert" ,"boolean" ,"break"}
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
/// 创建时间: 2022-08-11 最后一次修改时间:2022-08-11
public static string _Syntax_字符串_To_赋值数组值(this string sText)
{
String sValue = "{";
StringList_ sl = sText._Syntax_字符串_To_词汇列表();
for (int i = 0; i < sl.Count; i++)
{
sValue = sValue + "\"" + sl[i].Trim() + "\"";
if (i != sl.Count - 1)
{
sValue += ",";
}
}
sValue += "}";
StringBuilder sb = new StringBuilder(sText.Length + 100);
sb.Append("Java语法:\n String[] sArray = new String[]");
sb.Append(sValue);
sb.Append("\nC#语法:\n string[] sArray = new string[]");
sb.Append(sValue);
return sb.ToString();
}