例如:有两个字符串 string str1="STS09-南澳",string str2="S99NHG南海阁3"
去掉汉字和中划线以后,得到的值为:str1="STS09",str2="S99NHG3"
去掉汉字和中划线以后,得到的值为:str1="STS09",str2="S99NHG3"
解决方案 »
- 散分,请问个线程问题!
- 动态控件
- WinForm DataGrid滚动条控制
- vs2005与CVS
- 我想知道如何判断打印机的缺纸状态,以及当中的打印任务是否完成还是卡纸这类情况
- 诚意请教:如何用C#设计一个基于SVM算法的分类系统
- session 失效问题,没分了,,抱歉!!!
- See the end of this message for details on invoking just-in-time (JIT) debugging
- www.myvc.net征集斑竹
- c#选中datagirdview中的一行在picturebox里显示信息的图片
- C# winform 多个webBrowser设置多个代理
- [求助]DataGridView绑定数据源后的显示顺序问题
public static string CutString(string str, int length)
{
string tmp = str.Trim();
int i = 0, j = 0;
foreach (char chr in tmp)
{
if ((int)chr > 127)
{
i += 2;
}
else
{
i++;
}
if (i > length)
{
tmp = tmp.Substring(0, j) + "...";
break;
}
j++;
}
return tmp;
}
string[] strs = strCodeAndType.Split('-');把字符串分割成数组
string strCode = strs[0];得到-前的部分
string strCode = strs[0];得到-后的部分
<script>
/***去除中文函数****/
function CutChr()
{
var x=document.getElementById("text");
var str=x.value;
while(/[\u4E00-\u9FA5]+/.test(str)){
str=str.replace(/[\u4E00-\u9FA5]+/,"");
x.value=str;
}
}</script>
string str1="STS09-南澳";
string[] strs = str1.Split('-');把字符串分割成数组
string strCode = strs[0];得到-前的部分
string strCode1 = strs[0];得到-后的部分
这个方法 查下msdn就会用了
string str2 = "S99NHG南海阁3";
Regex oRegex = new Regex(@"[\u4E00-\u9FA5\-]*");
Response.Write(oRegex.Replace(str1, "")+"</br>");
Response.Write(oRegex.Replace(str2, ""));
这个可以。。用正则匹配中文和下划线。,,,用replace替换掉