B4A Library MLstrings library

This is a small library that adds functionality that I have written for other languages in the past and use frequently. I have ported them to a java lib for B4a. The MLStr object should be Dim'ed in Process_Globals.

Dim str As MLStr


Contents:

String Stripto(String line, String find)

Returns the contents of line up to the position of find, with the find character(s) stripped.

The remaining part of the line is returned in remainder. find can be a character or string.

If no match is found, stripto returns "". remainder is a stringbuilder and contains the remainder of the original line with the returned match deleted from it, INCLUDING the character searched for in find.

B4X:
Dim txt, tmp As String
     
     txt = "Jem : Miller : Oklahoma City"
     txt = stripto(tmp,":")  'will return "Jem " without the ":"
     
     tmp = remainder   'will equal " Miller : Oklahoma City" without the first ":"


String Proper(String line)

Uppercases the first letter of each word in line.


B4X:
name = "peter sellers"
 name = proper(name)


returns the propered line "Peter Sellers"


ToHex(long arg)

Converts a long or int number to a hexadecimal string

B4X:
Dim num As int
 Dim hex As String
 
 num = 1354
 hex = tohex(num)


String Unique()

Returns a unique String composed of the date and time (to the milisecond) in hexadecimal form

B4X:
 Dim txt As String
 
 txt = unique


String copies(char s, int n)

Returns a string of n number of s characters

B4X:
 Dim txt As String
 
 txt = copies("*", 8) 'returns "********"


String tab(int n)

Returns a string with n number of spaces

B4X:
dim tmp, txt as String
 
 tmp = "Names"
 
 txt = tab(40 - tmp.length) & tmp


int words(String st)

Returns the number of words in a string as an Int

B4X:
Dim gi As Int
 Dim txt As String
 
 txt = "this is a test"
 
 gi = words(txt)

gi will be 4


String wordn(String st, int wordnum)

Returns word number wordnum from the string st as a string.
Returns an empty string if wordnum is more than the word count.


String strip(String Line)

Strips all spaces from Line


String Mirt(String Line)

Trims all spaces from the beginning of the string Line

Useful for parsing strings with stripto

B4X:
Dim tmp, txt As String
 
 tmp = "This     is   a    formatted   line   "
 
 tmp = stripto(tmp," ")
 txt = remainder.tostring 'txt will equal "    is   a    formatted   line   "
 
 ' do something with tmp
 
 tmp = Mirt(txt) 'tmp will equal "is   a    formatted   line   "


String Escape(String Line)

Escapes all spaces in the string Line.

Required for some file handling methods, especially at the operating system level

This method converts the string:
"This is a test"

to:
"This\ is\ a\ test"

which Linux/Android can then understand.

Comments and suggestions always welcome.

--- Jem
 

Attachments

  • MLstring.zip
    4.5 KB · Views: 468
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Thanks, can be useful sometimes.
 

HotShoe

Well-Known Member
Licensed User
Longtime User
I hope so! :)

--- Jem
 

dunski

Member
Licensed User
Longtime User
Thank you

This is great. Very useful for what I'm doing. I have a lot of data to validate to avoid sql injection.
Makes my life a lot easier thank you.
:sign0142::sign0098:
 
Top