Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put space character into a string name in XML?

People also ask

How do I add a space to a string in XML?

Put   in string. xml file to indicate a single space in an android project.

How do you handle a space in XML?

XML ignores the first sequence of white space immediately after the opening tag and the last sequence of white space immediately before the closing tag. XML translates non-space characters (tab and new-line) into a space character and consolidates all multiple space characters into a single space.

Can you use spaces in XML?

In XML documents, there are two types of whitespace: Significant whitespace is part of the document content and should be preserved. Insignificant whitespace is used when editing XML documents for readability. These whitespaces are typically not intended for inclusion in the delivery of the document.

How do you space a string?

To add a space between the characters of a string, call the split() method on the string to get an array of characters, and call the join() method on the array to join the substrings with a space separator, e.g. str. split(''). join(' ') .


to use white space in xml as string use  . XML won't take white space as it is. it will trim the white space before setting it. So use   instead of single white space


Insert \u0020 directly in the XML for a blank you would like to preserve.

<string name="spelatonertext3">-4, \u00205, \u0020\u0020-5, \u00206, \u0020-6,</string>

Android doesn't support keeping the spaces at the end of the string in String.xml file so if you want space after string you need to use this unicode in between the words.

\u0020

It is a unicode space character.


This should work as well. Use quotes to maintain space

<string name="spelatonertext3">"-4,  5, -5,   6,  -6,"</string>

As already mentioned the correct way to have a space in an XML file is by using \u0020 which is the unicode character for a space.

Example:

<string name="spelatonertext3">-4,\u00205,\u0020-5,\u00206,\u0020-6</string>

Other suggestions have said to use &#160; or &#032; but there is two downsides to this. The first downside is that these are ASCII characters so you are relying on something like a TextView to parse them. The second downside is that &#160; can sometimes cause strange wrapping in TextViews.