MixedCase

NJDude

Expert
Licensed User
Longtime User
We currently have ToUpperCase and ToLowerCase but we are missing MixedCase, for example, if a string is entered as "some string value" with MixedCase we could format it as "Some String Value", that would be nice to have it as part of B4A instead of writing a routine to do just that.

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This will not be added to the core methods. However you can use this method:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim s As String
    s = ToMixCase("some string value")
    Log(s)
End Sub

Sub ToMixCase (s As String) As String
    Dim sb As StringBuilder
    sb.Initialize
    Dim m As Matcher
    m = Regex.Matcher("(^\w)|(\s\w)", s)
    Dim i As Int
    Do While m.Find
        If m.Match.Length > 1 Then    
            sb.Append(s.SubString2(i, m.GetStart(0) + 1))
            sb.Append(m.Match.SubString(1).ToUpperCase)
        Else
            sb.Append(s.SubString2(i, m.GetStart(0)))
            sb.Append(m.Match.ToUpperCase)
        End If
        i = m.GetEnd(0)
    Loop
    If i < s.Length Then
        sb.Append(s.SubString(i))
    End If
    Return sb.ToString
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…