次の形式の IP アドレスがあります。
1)20fe:f9..d3:93b1.58418
2)100.253.13.145:1346
"."
またはの最後のオカレンスを識別する Java プログラムを作成したいと考えています":"
。
基本的に、最後の「。」の後に発生するものはすべて切り捨てようとしています。また ":"
しかし、私はそのようなプログラムを書く方法がわかりません。いくつかのサンプルコードが役立ちます
For finding the last index of some character, String has a built-in method:
String.lastIndexOf(int ch)
So in your case:
yourVariable.lastIndexOf('.');
http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#lastIndexOf%28int%29
Then you can use this index to get the last part of the address(if that's what you want to do)
Try this code :
String [] parts = yourString.split("[.:]");
System.out.println("Last element is : " + parts[parts.Length -1]);