字符串里怎么能把数字和字母过滤出来?新手!谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/16 05:01:16
String s="hello1346word";
类似这样的

闲的无聊,简单写了个给你……事实上你最好用RegEx正则表达式,那样最快。但我手头没有C#环境,就用了笨方法。(其实是写完了才想起来用正则,但之前没用过C#的正则表达式)

PS:没有功劳有苦劳,能不能多给点分啊?

// WARN: Use Regular Expression if you can, this is
// only an alternative solution
// NOTE: function/method names may not be correct,
// since I don't have the develop environment
// Please use corrsponding methods if needed

// Author: Leemax Lee 20090302

public int SeperateStrings(String tar, out String[] numbers, out String[] strings) {
int count = 0; // counter
String temp = ""; // temporary
bool isThisNumber = false; // condition current
bool isLastNumber = false; // condition last
if (tar == NULL || tar.Length <= 0) return 0; // return if empty

// initial, clean up
tar = tar.Trim();
try {
Integer.ParseInt32(tar[0]);
isLastNumber = true;
} catch (Exception ignored) {<