Q
刪除字符串
4
A
回答
12
你只需要使用具有發現substring
右手食指在砍:
int index = myStr.indexOf('@');
// TODO: work out what to do if index == -1
String firstPart = myStr.substring(0, index);
編輯:相當明顯,上述發生之前第一@
的子字符串。如果你想在子前的最後@
你可以這樣寫:
int index = myStr.lastIndexOf('@');
// TODO: work out what to do if index == -1
String firstPart = myStr.substring(0, index);
5
相關問題
- 1. 刪除字符串
- 2. 刪除字符串
- 3. 刪除字符串
- 4. 刪除字符串
- 5. 刪除字符串
- 6. 刪除字符串
- 7. 刪除字符串
- 8. 刪除字符串
- 9. 字符串,刪除
- 10. 刪除字符串
- 11. 刪除字符串
- 12. 刪除字符串中的字符串
- 13. 從字符串中刪除字符串
- 14. 從字符串中刪除字符串
- 15. 使用擦除和刪除從字符串中刪除字符
- 16. Tcl刪除字符串後的所有字符而不刪除字符串
- 17. 從字符串中刪除
- 18. 刪除字符串從後
- 19. 刪除從字符串
- 20. 刪除字符串內容
- 21. 從字符串中刪除()
- 22. 刪除字符串外JSON
- 23. Matlab的 - 刪除字符串
- 24. 刪除 「」 從字符串
- 25. Jquery刪除字符串
- 26. 刪除字符串匹配
- 27. 刪除與字符串
- 28. Ruby - 刪除字符串?
- 29. 刪除'|'從字符串
- 30. 刪除包含字符串
它會永遠是一個電子郵件地址,你想要什麼之前@或者它只是一個你需要的子字符串? – talnicolas
它將始終是電子郵件格式 –
然後Jon Skeet的答案是 – talnicolas