Android Code Snippet Sanitize Hashtag strings

Code to make sure a string complies with "standard" Hashtag rules.
20-07-_2017_09-33-50.png

B4X:
Sub HashTagSanitizer(strText As String, bolForceLowercase As Boolean) As String
    Dim strRet As String = "#" & Regex.Replace2("[^a-z0-9_-]+", Bit.Or(Regex.MULTILINE, Regex.CASE_INSENSITIVE), strText, "")
    If bolForceLowercase Then
        Return strRet.ToLowerCase
    Else
        Return strRet
    End If
End Sub

The input...
B4X:
Log( HashTagSanitizer("#Test With Some words. Note the extra # here, which is n-o-t wanted", False)     )

results in...
#TestWithSomewordsNotetheextraherewhichisn-o-twanted


If there is a better way to accomplish this I would be glad to learn something new.
 
Top