Android Code Snippet Check for FortAwesome / Material Icon

Check for FontAwesome / Material Icon:
Private Sub CheckForFontAwesome(str As String) As Boolean
            ' Regex pattern to match "fa-" followed by a name.
            ' This will match strings like "fa-star", "fa-user-circle", etc.
            Dim faPattern As String = "fa-[a-z0-9-]+"

            Dim m As Matcher
            m = Regex.Matcher(faPattern, str)

            ' Matcher.Find returns True if any part of the string matches the pattern.
            Return m.Find
End Sub           

Private Sub CheckForMaterialIcon(str As String) As Boolean
            ' Regex pattern to match "material-icons" or "mi-" followed by a name.
            Dim MaterialPattern As String = "(material-icons|mi)-[a-z0-9_]+"

            Dim m As Matcher
            m = Regex.Matcher(MaterialPattern, str)

            ' Matcher.Find returns True if any part of the string matches the pattern.
            Return m.Find
End Sub
 

AnandGupta

Expert
Licensed User
Longtime User
Sorry, can you give example how to use it and when ?
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I am parsing a PDF and the fields are relative to the start of the line.

On one of the PDFs a user put a FontAwesome Star before one of the name (so all the fields got pushed down one).

The text came in to me as "fa-star" (which is the FontAwesome Star) but to my program just looked like what could be a persons name (right, it is just text)
But that push the name field to where I was looking for numbers and everything go missed aligned. (wish I had an example of the PDF but no longer have access)

So while processing the fields that come in if ANY of them is a FontAwesome or MaterialFont I just skip it (treat it like garbage - which to me it is)

Not sure if this example will help. Take into to mind that I am processing the fields relative to start of line
B4X:
                            If  Offset = Hdr.NameAt Then
                                '-----------------------------------------------------------------------------------------
                                '    Look to see if this string is actually a Font Awesome or Material Icon character
                                '-----------------------------------------------------------------------------------------
                                If  CheckForFontAwesome(Value) Or CheckForMaterialIcon(Value)  Then
                                    Continue
                                End If                                

                                 Player.Name = Value
                            else if ....
                            End If

Hope this helps - If I get access to the PDF again I will screen shot the section and post it
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…