Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
この文字列について、16.82080560, 96.13055810取得したい
16.82080560, 96.13055810
"String one = 16.82080560"
と
"String two = 96.13055810"
アンドロイドで。 文字列操作と正規表現が苦手な管理者。 文字列からそのような 2 つの値を取得する方法を教えてください。
String[] components = original.split(",");
文字列が常にコンマで区切られている場合は、使用できますString.split
String.split
より良い正規表現パターンについては、次のコメントを参照してください@npinti。
@npinti
マイナーな補足として、単に , の代わりに \\s*,\\s* を実行する方がよい場合があります。2 番目の数値の先頭にある余分な空白は適切な数値として認識されない可能性が高いため、OP がこれらを浮動小数点数にキャストしたい場合に問題が発生する可能性があります。