Android Question StringFunctions Proper Case problems

Q Candiani

Licensed User

Sometimes, when I use the Proper functions of library StringFunctions, my app remains "processing" something and does not continue. There is no error, no log.

For example:

If IsNumber(txt_cuit.Text) Then
    Starter.type_request = "GET"
    Starter.url_request = "app/x007s/cuit/" & txt_cuit.Text & "/"
    wait for request_complete
    If Starter.success_request Then
        Dim jp As JSONParser
        Dim respond As List = jp.NextArray
        If respond.Size > 0 Then
            For Each case As Map In respond
                Dim texto As String
                texto = Starter.sf.Proper(case.Get("social"))
                lab_name.Text = texto.trim
        End If
    End If
End If

App remains on 'texto = Starter.sf.Proper(case.Get("social"))'. And nothing happens.
Any idea?

Q Candiani

Licensed User
Hi, Erel.

According to this link, 'proper method' capitalizes strings.

What other library or method would you recommend instead of stringfunction.proper?
Upvote 0


Staff member
Licensed User
Use the built in string methods. See the strings video tutorial:

Title case:

Sub TitleCase (s As String) As String
   s = s.ToLowerCase
   Dim m As Matcher = Regex.Matcher("\b(\w)", s)
   Do While m.Find
       Dim i As Int = m.GetStart(1)
       s = s.SubString2(0, i) & s.SubString2(i, i + 1).ToUpperCase & s.SubString(i + 1)
   Return s
End Sub
Upvote 0


Well-Known Member
Licensed User
I made Erel's Proper (Title) case work with a b4xFloatTextField using this:
(Set the event name to b4XFloat on any Proper case text fields)
Sub b4xFloat_TextChanged (Old As String, New As String)
    If New.ToLowerCase <> Old.ToLowerCase Then   'this makes it only fire once
        Dim b4xView As B4XFloatTextField
        b4xView = Sender
        Dim edtText As EditText
        edtText = b4xView.TextField
        edtText.Text = TitleCase(New)
        edtText.SelectionStart = edtText.Text.Length
    End If
End Sub

I have to set the SelectionStart to the end or it will add characters in reverse order within the TitleCase...
It works for me, but I'd be very interested in better methods...

P.S. I commented out this line in the TitleCase function to allow embedded upper case like "McDonald"
' s = s.ToLowerCase
Last edited:
Upvote 0