1

次のように、ベクトルの加算によって配列を取得しました [1!,2!,3!,4!]

私はそれを次のような文字列に変換する必要があります

{1!2!3!4!}

..私がそれを作ることができるいくつかの方法の名前を教えてもらえますか? 皆さんありがとう..

String getElement = null;
             for(int j = 0;j<5;j++){
             getElement = dynamicViewtagNames.elementAt(j);

             }

この配列の要素を次のように取得できます。次に、それを文字列に変換する必要があります。

4

3 に答える 3

0

あなたの質問を正しく理解しているかどうかはわかりませんが、これを変えたいだけなら:

[1!,2!,3!,4!]

の中へ

{1!2!3!4!}

たとえば、String.replace()またはString.replaceAll()メソッドを利用できます。

String str = "[1!,2!,3!,4!]";
str = str.replace("[", "{");
str = str.replace("]", "}");
str = str.replace(",", "");

[1!,2!,3!,4!] が上で示した文字列を含むベクターの場合、 StringBufferを使用して次のように実行できます。

// letz assume this vector has the following content: [1!,2!,3!,4!]
Vector<String> dynamicViewtagNames = new Vector<String>(); 

StringBuffer b = new StringBuffer();

b.append("{");

for(int i = 0; i < dynamicViewtagNames.size(); i++) {
    b.append(dynamicViewtagNames.get(i))
}

b.append("}");
String mystring = b.toString();
于 2013-08-16T12:01:53.807 に答える
0

シンプルなソリューション

 String names = names.replaceAll(",","");
 names = names.replaceAll("[", "{");
 names = names.replaceAll("]", "}");
于 2013-08-16T12:05:19.513 に答える
0

このコードを使用して、

StringBuilder str = new StringBuilder();

for (int i = 0; i<dynamicViewtagNames.length;i++){
    str.append(dynamicViewtagNames[i])
}

str.toString();

または次を使用できます。

Arrays.toString(dynamicViewtagNames);

ありがとう

于 2013-08-16T12:09:48.320 に答える