當前位置:首頁 » 凈水方式 » 過濾字元串中的數字

過濾字元串中的數字

發布時間: 2021-01-20 06:48:21

㈠ 只要字元串的 數字,半形-,半形* ,其它字元全部過濾掉,JAVA中正則該怎麼寫

String str="0551-5108585、5106616 磬苑: 0551-3861678";
str.replaceAll("[^-*\\d]","");

㈡ 如何用正則表達式去除一個字元串裡面的數字和小數點以外的字元

1、新建java文件,TestRegexp.java;

㈢ java 正則過濾字元串穿中的數字開頭字元

可以。Java正則表達式:32="1"\s+59="0000"

完整的程序如下:專

publicclassLL{
publicstaticvoidmain(String[]args){
Strings="<root><users><userid="2739751"ccted="0000000000"32="1"59="0000"name="張非"></user></users></root>";
System.out.println(s.replaceAll("32="1"\s+59="0000"",""));
}
}

運行屬結果:

<root><users><user id="2739751" ccted="0000000000" name="張非"></user></users></root>

㈣ c語言初學 如何過濾字元串中除了字母與數字中的字元 例如我輸入123abcABC!@#123 輸

只能說找出數字0到9和字母a到z,這個得用到字元串函數(比如char *strpbrk(char *str1, char *str2);),內因為在編程語言容中,只認字元,而你所提到的其他符號都是字元,計算機是無法區別的。

㈤ 怎麼去除string字元串中的純數字字元串

用Java正則表達式來把字元串源str變成"A45;J10;G3;",再用分號切分字元串,就行了
完整的Java程序如下(關鍵點見注釋)

publicclassCC{
publicstaticvoidmain(String[]args){
Stringstr="123;A45;33;J10;G3;122";
Strings=str.replaceAll("\b[0-9]+(;|$)\b","");//用Java正則表達式去掉純數字字元串
System.out.println(s);
Stringa[]=s.split(";");//以分號切分字元串
//輸出數組a
Stringresult="{";
for(inti=0;i<a.length;i++){
if(i==a.length-1){
result=result+a[i];
}else{
result=result+a[i]+",";
}
}
result=result+"}";
System.out.println(result);
}
}

運行結果
A45;J10;G3;
{A45,J10,G3}

㈥ java怎麼去除字元串中的數字。。。

publicclassHello{
publicstaticvoidmain(String[]args){
Stringstr="123assume345contribute";
System.out.println(str.replaceAll("\d+",""));
}
}

㈦ 用c語言提取字元串中的數字

用c語言提取字元串中的數字的操作如下:

1、首先打開visual studio軟體並創建一個新的c語言專文件,如屬下所示。

㈧ js正則表達式怎麼取出個字元串中的所有數字,急急急

對於字元s,利用正則匹配 :varnum=s.replace(/[^0-9]/ig,"")。

㈨ 字元串里怎麼能把數字和字母過濾出來新手!謝謝

閑的無聊,簡單寫了個給你……事實上你最好用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) {
isLastNumber = false;
}

// loop
for (int i = 0; i < tar.Length; i++) {
try {
Integer.ParseInt32(tar[i]);
isThisNumber = true;
} catch (Exception ignored) {
isThisNumber = false;
}
if (isThisNumber != isLastNumber) {
count++; // counter increment
if (isLastNumber) {
numbers.add(temp);
} else {
strings.add(temp);
}
temp = new String("");
}

// store current character
temp += tar[i];
isLastNumber = isThisNumber;
}

// save the last one
if (isThisNumber != isLastNumber) {
count++;
if (isLastNumber) {
numbers.add(temp);
} else {
strings.add(temp);
}

return count;
}

㈩ java中,正則表達式,如何過濾除數字和字母之外的其它字元

\w A word character: [a-zA-Z_0-9]
\W A non-word character: [^\w]

熱點內容
丁度巴拉斯情人電影推薦 發布:2024-08-19 09:13:07 瀏覽:886
類似深水的露點電影 發布:2024-08-19 09:10:12 瀏覽:80
《消失的眼角膜》2電影 發布:2024-08-19 08:34:43 瀏覽:878
私人影院什麼電影好看 發布:2024-08-19 08:33:32 瀏覽:593
干 B 發布:2024-08-19 08:30:21 瀏覽:910
夜晚看片網站 發布:2024-08-19 08:20:59 瀏覽:440
台灣男同電影《越界》 發布:2024-08-19 08:04:35 瀏覽:290
看電影選座位追女孩 發布:2024-08-19 07:54:42 瀏覽:975
日本a級愛情 發布:2024-08-19 07:30:38 瀏覽:832
生活中的瑪麗類似電影 發布:2024-08-19 07:26:46 瀏覽:239