Android Question Create String Resource with , in the string

corwin42

Expert
Licensed User
Longtime User
Hello,

I'm trying to create something like this in the Manifest:

B4X:
CreateResource(values, strings.xml,
<resources>
    <string name="accessibility_description">Some Text, Some more text</string>
</resources>
)

The problem is the "," in the text. I think the CreateResource function thinks that there starts another parameter.
How can I create such strings? Is there something like an escape character?
 

corwin42

Expert
Licensed User
Longtime User

Thanks. Replacing the comma with &#44; works. But I guess this is somehow a workaround for a CreateResource limitation. I'm sure you won't have to do it in an XML file.

Can't find comma specifically. but it looks like a '\' is an escape character, worth a try.

I tried a backslash but the problem is that the Syntax parser breaks up the parameter at the comma and a backslash is of no help in this case.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Maybe

Source
B4X:
 If you have an apostrophe (') in your string, you must either escape it with a backslash (\') or enclose the string in double-quotes (""). For example, here are some strings that do and don't work:

<string name="good_example">This\'ll work</string>
<string name="good_example_2">"This'll also work"</string>
<string name="bad_example">This doesn't work</string>
    <!-- Causes a compile error -->

Did you tried to enclose the String (including comma) with quotes (")?
B4X:
CreateResource(values, strings.xml,
<resources>
    <string name="accessibility_description">"Some Text, Some more text"</string>
</resources>
)
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
B4X:
CreateResource(values, strings.xml,
<resources>
    <string name="accessibility_description">"Some Text, Some more text"</string>
</resources>
)
Yep. The comma is still a problem.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
there's also the CDATA method that's used for content where you're not sure of what it might contain.
 
Upvote 0
Top