111,129
社区成员
发帖
与我相关
我的任务
分享
string _expressionDIY = "百位*3-十位+2+个位*个位";
string[] _a = new string[] { "百位", "十位", "个位" };
for( int i = 0; i < _a.Length ;i++)
{_expressionDIY= _expressionDIY.Replace(_a[i], "," + _a[i] + ",");}
_b = _expressionDIY.Split(",".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries );
string _expressionDIY = "百位*3-十位+2+个位*个位";
string[] strP = new string[]{"百位","十位","个位"};
List<string> listStr = new List<string>();//结果
while(_expressionDIY.Length>0)
{
bool flag = false;
int index = 0;
for(int i=0;i<strP.Length;i++)
{
int _index = _expressionDIY.IndexOf(strP[i]);
if(_index == 0)
{
flag = true;
listStr.Add(strP[i]);
_expressionDIY = _expressionDIY.Substring(strP[i].Length);
break;
}
if (_index == -1) continue;
if(index == 0 || _index<index) index = _index;
}
if(flag) continue;
if (index == 0) index = _expressionDIY.Length;
listStr.Add(_expressionDIY.Substring(0,index));
_expressionDIY = _expressionDIY.Substring(index);
}