如何把字符串"TP计算机技术"中的"TP"两个字母截取下来? 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string str1 = "TP计算机技术"中的";string str2 = str1.SubString(0,2); String myString="TP计算机技术"myString.replace("TP","") string str1 = "TP计算机技术"中的";string str2 = str1.SubString(0,2); 上面的py都是特定的截取,我写个小程序(也花了15分钟阿),可以得到字符串中开始部分所有大小写子母,当读到不是字母的部分时,停止读取。你自己研究吧,更复杂字符处理你可以使用正则表达式using System;using System.IO;using System.Text;namespace ConsoleApplication2{ class Class1 { [STAThread] static void Main(string[] args) { string sourceString = "TP中国"; StringBuilder s = new StringBuilder(); int ptr = 0; while(ptr<sourceString.Length) { char temp = sourceString[ptr]; if(Char.IsLower(temp)||Char.IsUpper(temp)) { s.Append(temp.ToString()); } else { ptr=sourceString.Length;//退出循环 } ptr++; } Console.WriteLine(s.ToString()); Console.Read(); } }} string str="TP中国";s1=Regex.Replace(str,@"[\u4e00-\u9fa5]*","");//s1=TP 我的要求是能做到把字母、数字和中文混合在一起的字符串中的字母和数字截取下来比如:A马克思 取出 A TP01计算机科学与技术 取出 TP01怎么实现啊? 谢谢sgd(阿司)了,你的方法可行,我解决了问题。 关于WebService区分不同的用户 不知道什么原因,UpdatePanel刷新DropDownList的问题 谁知道这句代码啥意思? C#中的拖动问题 关于FileSystemWatcher和PermissionSet的问题 问一个继承的问题 怎样在openfileDialog里面实现多种路径获取?? C#+ASP.NET 写的程序中,要打开一个Word文件,然后在word文件的某个位置插入一张图片(签名),怎么做? 超级变态自定义TEXTBOX 小菜问题:函数怎么用?急呀!答对就给分! 很容易就能得分!帮帮忙! 在webform中使用TreeView控件的怪问题?
string str2 = str1.SubString(0,2);
myString.replace("TP","")
string str2 = str1.SubString(0,2);
写个小程序(也花了15分钟阿),可以得到字符串中开始部分所有大小写子母,当读到不是字母的部分时,停止读取。你自己研究吧,更复杂字符处理你可以使用正则表达式
using System;
using System.IO;
using System.Text;
namespace ConsoleApplication2
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string sourceString = "TP中国";
StringBuilder s = new StringBuilder();
int ptr = 0;
while(ptr<sourceString.Length)
{
char temp = sourceString[ptr];
if(Char.IsLower(temp)||Char.IsUpper(temp))
{
s.Append(temp.ToString());
}
else
{
ptr=sourceString.Length;//退出循环
}
ptr++;
}
Console.WriteLine(s.ToString());
Console.Read();
}
}
}
s1=Regex.Replace(str,@"[\u4e00-\u9fa5]*","");//s1=TP
比如:A马克思 取出 A
TP01计算机科学与技术 取出 TP01
怎么实现啊?