Android Question StringFunctions Proper Case problems

Q Candiani

Member
Licensed User
Hello,

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:

B4X:
If IsNumber(txt_cuit.Text) Then
    Starter.type_request = "GET"
    Starter.url_request = "app/x007s/cuit/" & txt_cuit.Text & "/"
    send_request
    wait for request_complete
    If Starter.success_request Then
        Dim jp As JSONParser
        jp.Initialize(Starter.response)
        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
            Next
        End If
    End If
End If
App remains on 'texto = Starter.sf.Proper(case.Get("social"))'. And nothing happens.
Any idea?
 

Erel

Administrator
Staff member
Licensed User
Don't use StringFunctions.

What does Proper method do?
 

Q Candiani

Member
Licensed User
Hi, Erel.

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

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

Erel

Administrator
Staff member
Licensed User
Use the built in string methods. See the strings video tutorial: https://www.b4x.com/etp.html

Title case:

B4X:
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)
   Loop
   Return s
End Sub
 

Rusty

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)
B4X:
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...
Rusty

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