Q Q Candiani Member Licensed User Longtime User Feb 13, 2019 #1 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: Code: Copy 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?
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: Code: Copy 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 B4X founder Staff member Licensed User Longtime User Feb 13, 2019 #2 Don't use StringFunctions. What does Proper method do? Upvote 0
Q Q Candiani Member Licensed User Longtime User Feb 13, 2019 #3 Hi, Erel. According to this link, 'proper method' capitalizes strings. What other library or method would you recommend instead of stringfunction.proper? Upvote 0
Hi, Erel. According to this link, 'proper method' capitalizes strings. What other library or method would you recommend instead of stringfunction.proper?
Erel B4X founder Staff member Licensed User Longtime User Feb 13, 2019 #4 Use the built in string methods. See the strings video tutorial: https://www.b4x.com/etp.html Title case: Code: Copy 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 Upvote 0
Use the built in string methods. See the strings video tutorial: https://www.b4x.com/etp.html Title case: Code: Copy 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
Q Q Candiani Member Licensed User Longtime User Feb 13, 2019 #5 Thanks, Erel! It works perfectly! Upvote 0
Rusty Well-Known Member Licensed User Longtime User May 19, 2019 #6 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) Code: Copy 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: May 19, 2019 Upvote 0
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) Code: Copy 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
N noeleon Active Member Licensed User Longtime User Apr 13, 2023 #7 Erel said: 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 Click to expand... This function does not work correctly when there's an apostrophe in a word. For example: don't becomes Don'T How to fix this? Upvote 0
Erel said: 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 Click to expand... This function does not work correctly when there's an apostrophe in a word. For example: don't becomes Don'T How to fix this?
aeric Expert Licensed User Longtime User Apr 13, 2023 #8 noeleon said: This function does not work correctly when there's an apostrophe in a word. For example: don't becomes Don'T How to fix this? Click to expand... Please start a new thread. Upvote 0
noeleon said: This function does not work correctly when there's an apostrophe in a word. For example: don't becomes Don'T How to fix this? Click to expand... Please start a new thread.