Android Question wordwrap code

hub73

Active Member
Licensed User
Longtime User
hi !
is somebody have a code sample to wordwrap a string ?

for example :

wordwrap (Input as String, Length as Int)

B4X:
MyString = "fsdfsdfdsfsdf fdsfsdfsdfsd fdsfsdfsdfsdf fdsfsdfsdfdsf fdsfsdfsdf"

MyString = wordwrap (MyString, 13)

tranform MyString to :

"fdsfdsfdsffsd(CRLF)fdfdf fdsfsffd(CRLF)dqsddsq dsq(CRLF)fsdsfsdfsdff(CRLF)

or into an array.

Thanks
 

mangojack

Well-Known Member
Licensed User
Longtime User
This adds string sections to a list .. courtesy @stevel05
B4X:
Dim myList As List
myList.Initialize
Dim myString As String = "This is a long string which will be split into individual set size strings"

Wordwrap(myString, 13)

Sub Wordwrap (str As String, count As Int)

  myList.Clear
  str = str.Replace(" ", "")
  For i = 0 To str.Length - count Step count
  myList.Add(str.SubString2(i, i + count))
  Next

  'add remainder of string
  myList.Add(str.SubString(i))

End Sub
 
Last edited:
Upvote 0
Top