2

この方法についてサポートが必要です。

String d = ret.getData(); //I get the string using this
int ui;
ui = d.indexOf("=", d.indexOf("=")+1);
do{
int f=d.indexOf("=", ui+1 );
System.out.println(d.substring(ui+1, f-1));//Here I'm showing the results of my code
ui = ui + d.indexOf("=", ui);}
while ((d.indexOf("=") + ui)!= 0);

私が持っている文字列はこれです:

!re
=.id=*1
=name=ether1
=mtu=1500
=l2mtu=1600
=mac-address=D4:CA:6D:37:44:26
=arp=enabled
=auto-negotiation=true
=full-duplex=true
=speed=100Mbps
=running=true
=slave=false
=disabled=false

そして、私のコードの結果は次のとおりです。

*1
ether1
l2mt
24:22
nin

そして、私が取得したいのは:

*1
ether1
1500
1600
D4:CA:6D:37:44:26
enabled
true
true
100Mbps
true
false
false

「=」の後にあるものをすべて取得する必要があります

助けてください!ありがとう

4

5 に答える 5

0

string.split 関数 by を使用して文字列を分割してみてください=。文字列の配列を返します。for ループで 2 回インクリメントし、出力を表示します。

于 2013-02-26T17:36:15.680 に答える
0

スプリッターが役立ち、それが最も簡単で正しい方法です。ただし、逆に鼻に触れたい場合、または別の方法を探している場合は、正規表現/パターン マッチャーを使用できます。:-)

public static void main(String[] args) {
    TestClass test = new TestClass();


    String d = "=mtu=1500"; //I get the string using this
    Scanner scan = new Scanner(d);
    System.out.println(scan.nextLine().split("=")[2]);


}

これは印刷されます - 1500

于 2013-02-26T17:36:20.803 に答える
0

メソッドを使用d.split("=")して、結果の配列の最新の値を取得できます

于 2013-02-26T17:30:07.193 に答える
0

これを行うだけです。

Scanner scan = new Scanner( ret.getData() );
scan.nextLine(); //skip the first line

While (scan.hasNextLine()){
     String s = scan.nextLine();
     int index = s.lastIndexOf("=");
     System.out.println(s.substring(index+1));
}
于 2013-02-26T17:31:53.040 に答える
0

おそらく、「=」を区切り文字としてScannerを使用できます。scanner.next() を実行し、各トークンを読み込むだけです:)

于 2013-02-26T17:27:14.057 に答える