文字列の範囲を分離
この資料では、文字列の範囲を分離するのに役立ちます. チェーンを持つ例
"-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でこれについてのすべてを編集するときに特定の今夜作られています, ユーザーが永遠に新しいを見つける方法を見ます.



彼は、なぜ彼Linux上のパイプがあることに気づいた電子のUIを求め. トピックがあると子供たちは、グループのエッセイを行います ” パイプについて学びます, インストール 1 Linuxのオペレーティング・システム・ソフトウェア” しかし、彼は再びvay.hicとして提案しました… 私たちは多くのHIUをK E….
を支援するための唯一の願い.
これはあなたの不明=です)) ない、これまで反対, あなたはキーワードでGoogle検索を試してみてください
Linuxでのパイプ
またはLinuxでのパイプ