1

I have a string in my string.xml whose structure is like this.

string.xml

<string name="my" formatted="false">As*#*Bs*#*Cs</string>

and I am fetching this string in my main file like this.

main.java

String h1 = getResource().getString(R.string.my);

and my output is like this.

h1=As*#*Bs*#*Cs

but I want output in an array without regex like this.

h1[0]="As",h1[1]="Bs",h1[2]="Cs";

What should I change to get the above output? Any help would be appreciated

1
  • <string name="you">%$&amp;my(0)*#*hello*#*bye</string> what should i do for this mean now i want output in which i should get hello,bye,the element on h1[0] index Commented Sep 11, 2012 at 12:50

3 Answers 3

1

Have you tried?

String[] stringArray = h1.split("\\*#\\*");
Sign up to request clarification or add additional context in comments.

Comments

1

I advise you to store your string as a string array in the following manner :

<resources>
    <string-array name="my">
        <item>As</item>
        <item>Bs</item>
        <item>Cs</item>
    </string-array>
</resources>

You will be able to retrieve you array in the following manner :

String [] h1 = getResources().getStringArray ( R.array.my );

Comments

0

After stroring your xml string in h1 String . You need to apply split on h1 string.

Try this.

String h1= "As*#*Bs*#*Cs";
String[] test = h1.split("\\*#\\*"); 

for(String str : test)
{
      Log.i("==============", str);
}

Output :

I/==============( 1321): As
I/==============( 1321): Bs
I/==============( 1321): Cs

You can use str[0] , str[1] and str[2] to get respective string.

1 Comment

<string name="you">%$&amp;my(0)*#*hello*#*bye</string> i want output like this from this string like this output[0]=h1[0]="As", output[1]="hello",output[2]="bye"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.