0

Please, explain me how can I add a new line in xml only (when I will use this string in program this must be single line)?

For example:

<string name="test">This
is
test
line</string>

But in program when I will use getString(R.string.test); it will load single string without some new line characters: This is test line.
I need this only for file formatting.

Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
  • 3
    Should be '\n' See: http://stackoverflow.com/questions/8693544/carriage-returns-line-breaks-with-n-in-strings-in-android – Morrison Chang Feb 25 '16 at 23:09
  • I need to understand how to split a long string in some strings in xml only. To I don't need in any actions in java code when I will use this string. When I will load this string resource all `new line` characters in xml must disappear. – Denis Sologub Feb 25 '16 at 23:13
  • Just I have fixed file string length (80 characters per string in code and xml files) and want format my long strings for better view. – Denis Sologub Feb 25 '16 at 23:14
  • 1
    Not clear on your ask. If `This\nis\ntest\nline` isn't what you are looking for, perhaps this is: http://stackoverflow.com/questions/10862975/how-to-put-space-character-into-a-string-name-in-xml – Morrison Chang Feb 25 '16 at 23:30
  • Thanks! Just I think that if xml parses single spaces then it will parse `new line` characters too. – Denis Sologub Feb 25 '16 at 23:34

1 Answers1

1

If you want to force a newline in the XML string just use '\n' (assuming your TextView is sized properly):

<string>This\nis\ntest\nline</string>

Output

This
is
test
line

See: How to insert a new line in strings in Android

Otherwise you can inject in a blank space &#032; or &#160; for adjusting your string formatting.

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

Community
  • 1
  • 1
Morrison Chang
  • 11,691
  • 3
  • 41
  • 77