[英]Splitting string into substring in Java
我有一個字符串,我想用Java將其拆分為子字符串,最初的字符串是這樣的
Node( <http://www.mooney.net/geo#wisconsin> )
現在我想用(#)將其拆分為子字符串,這是我的代碼
String[] split = row.split("#");
String word = split[1].trim().substring(0, (split[1].length() -1));
現在這段代碼可以正常工作了,但它給了我
"wisconsin>"
我想要的最后一個作品只是“威斯康星州”的作品,沒有“>”這個標志,如果有人有想法請幫助我,在此先感謝。
實際上,它的輸出為"wisconsin> "
(包括空格)
使subString()
為
String word = split[1].trim().substring(0, (split[1].length()-3));
然后您將獲得輸出為
wisconsin
教程Point String subString()方法參考
String string =“在此輸入零件”;
String []部分= string.split(“-”);
字符串part1 = parts [0];
字符串part2 = parts [1];
您可以像以前一樣再次拆分(用>代替#),並使用元素[0]而不是[1]
考慮
String split[] = row.split("#|<|>");
它提供了這樣的String
數組,
{"http://www.mooney.net/geo", "wisconsin"}
獲取最后一個元素,索引為split.length()-1
。
您可以使用replace like。
word.replace(char oldChar,char newChar)
希望能有所幫助
您可以使用Java String Class的subString()方法。
請參考此鏈接 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.