分离字符串范围
本文将帮助你从字符串分隔范围. 例如,该串
"-1.223 %^& fsf 0.234 56.65 fsf 9 f"
我们将走出杯:
-1.223 0.234 56.65 9

在这里,它在C和Java成功实施, 其他语言也使 ;). 补充说,怎么可以用它来 正则表达式, 你不清除可以阅读更多关于它.
在C: 其实这是我所有的参考和发展 如何从字符串在C提取号码
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
// khong doc duoc str khi bat dau bang dau tru (-)
char* str= "-1.223 %^& fsf 0.234 56.65 fsf 9 f";
// khai bao, cap phat bo nho them s de cong them vao dau 1 ky tu
char* const s = (char*)malloc(sizeof(strlen(str))+1);
// cong them ky tu a
strcpy(s, "a");
strcpy(s + strlen(s), str);
printf("%s\n",s);
// tach lay cac so
int total_n = 0;
int n;
float i; // cac so can tach
printf("\nday cac so\n");
while (1 == sscanf(s + total_n, "%*[^0123456789-]%f%n", &i, &n))
{
total_n += n;
printf("%f\n", i);
}
return 0;
}
在Java: 最简单的方法是把所有的非数字字符 (除负, 点) 然后分离成以下元件:
public class ScanArrayNumFromString {
public static void main(String[] args) {
// chuoi ban dau
String str = "-1.223 %^& fsf 0.234 56.65 fsf 9 f";
/**
* thay the toan bo nhung ky tu khong phai so, khong phai dau am, khong
* phai dau cham bang dau phay
*/
str = str.replaceAll("[^0-9,-\\.]", ",");
/** cat thanh cac phan tu thong qua dau phay */
String[] item = str.split(",");
// duyet cac phan tu, neu la so thi in ra
for (int i = 0; i < item.length; i++) {
try {
Double.parseDouble(item[i]);
System.out.println(item[i]);
} catch (NumberFormatException e) {
}
}
}
}
职位时,一定你今晚,因为所有关于我在C解决这个执行, 期待看到过使用.



他要求电子UI意识到,管道上的Linux就是为什么他. 组文章,你做的题目 ” 学习管道, 安装 1 软件在Linux操作系统” 但老师建议作为vay.hic… 我们êķ多HIU….
只是一个愿望,以帮助.
这是不明确=)) 不反对过, 尝试谷歌搜索关键字
管仲的Linux
在linux乙酸管