3

In strings.xml

Lets say I have the following strings:

<string name="CourseInfo">Course Information</string>
<string name="CourseInfo1">Course Information:</string>
<string name="CourseInfo2">Course Information:-</string>

As you can see the string is the same, the only difference is that the second one has a colon and the third one has a colon and a dash.

Is this the most optimal way to do this? It seems kinda repetitive to do it this way.

3
  • Do it programatically when needed. getResources.getString(...) + ":-" ; or + ":"; ? Commented Aug 30, 2013 at 14:38
  • @ShobhitPuri Is that the only way to do it? Commented Aug 30, 2013 at 14:39
  • No idea. Lets wait for other answers. If there is an another way I would be glad to know :) Commented Aug 30, 2013 at 14:40

1 Answer 1

1

maybe you can use some thing like

<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>

see http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling

so for your example

<string name="CourseInfo2">Course Information%1$s</string>

and then

Resources res = getResources();
String text = String.format(res.getString(R.string.CourseInfo2), ":");
String text2 = String.format(res.getString(R.string.CourseInfo2), ":-");
Sign up to request clarification or add additional context in comments.

1 Comment

this doesn't consider localization that would be necessary for a different language

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.