[英]Copy a string until character found in Java
Hello I was wandering how can I copy a piece of a String in Java until a character/symbol is found. 你好我在徘徊如何在Java中复制一段字符串,直到找到一个字符/符号。 In my case the original string is:
"hello.1234"
and I want only "hello"
, so that every thing after the symbol .
在我的情况下,原始字符串是:
"hello.1234"
,我只想"hello"
,所以符号之后的所有东西.
is discarded. 被丢弃了。
Any idea? 任何想法? many thanks
非常感谢
EDIT: 编辑:
solved as follows: 解决如下:
String partBeforeFullStop = input.split("\\.")[0];
Use String#indexOf(int)
and String#substring(int)
. 使用
String#indexOf(int)
和String#substring(int)
。
String input = "hello.1234";
String output = input.substring(0, input.indexOf('.'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.