Android Question How to include a new line character in a string

toby

Well-Known Member
Licensed User
Longtime User
B4X:
Private const weekdays() As String=Array As String("Monday Lundi", "Tuesday Mardi", "Wednesday Mercredi")

When each string is assigned to a label view, I want the second word to appear on a line below.

For example, instead of showing
Monday Lundi

What I want to see is
Monday
Lundi

How to achieve that without using CsBuilder?

TIA
 
Solution
B4X:
)Private const weekdays() As String=Array As String("Monday Lundi", "Tuesday Mardi", "Wednesday Mercredi"

When each string is assigned to a label view, I want the second word to appear on a line below.

For example, instead of showing
Monday Lundi

What I want to see is
Monday
Lundi

How to achieve that without using CsBuilder?

TIA

Try this:
B4X:
Private const weekdays() As String=Array As String("Monday & CRLF & Lundi", "Tuesday & CRLF & Mardi", "Wednesday & CRLF & Mercredi"

You can also try to use CHR$(10) instead of CRLF.

BlueVision

Active Member
Licensed User
Longtime User
B4X:
)Private const weekdays() As String=Array As String("Monday Lundi", "Tuesday Mardi", "Wednesday Mercredi"

When each string is assigned to a label view, I want the second word to appear on a line below.

For example, instead of showing
Monday Lundi

What I want to see is
Monday
Lundi

How to achieve that without using CsBuilder?

TIA

Try this:
B4X:
Private const weekdays() As String=Array As String("Monday & CRLF & Lundi", "Tuesday & CRLF & Mardi", "Wednesday & CRLF & Mercredi"

You can also try to use CHR$(10) instead of CRLF.
 
Upvote 1
Solution

toby

Well-Known Member
Licensed User
Longtime User
Try this:
B4X:
Private const weekdays() As String=Array As String("Monday & CRLF & Lundi", "Tuesday & CRLF & Mardi", "Wednesday & CRLF & Mercredi"

You can also try to use CHR$(10) instead of CRLF.
Thanks to your help, I've ended up with the following
B4X:
Private const weekdays() As String=Array As String($"Monday${CRLF}Lundi"$, $"Tuesday${CRLF}Mardi"$, $"Wednesday${CRLF}Mercredi"$)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Why didn't you just leave it like you originally had it and simply replace the space with crlf using the replace function when you need a given element of the array
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
Why didn't you just leave it like you originally had it and simply replace the space with crlf using the replace function when you need a given element of the array
Because those strings are constant. I just want to keep it simple:)
 
Upvote 0
Top