iOS Code Snippet A good thing for you MarkPatternCSbuilder

Hi
I could detect link or any thing with Regex in android and use it
But in B4i i had problem about convert my custom pattern to link
Now with below code you can convert any string with pattern to link
B4X:
Sub MarkPatternCSbuilder(Input As String, Pattern As String, GroupNumber As Int) As CSBuilder
   Dim cs As CSBuilder
   cs.Initialize
   Dim lastMatchEnd As Int = 0
   Dim m As Matcher = Regex.Matcher(Pattern, Input)
   Do While m.Find
       Dim currentStart As Int = m.GetStart(GroupNumber)
       cs.Append(Input.SubString2(lastMatchEnd, currentStart))
       lastMatchEnd = m.GetEnd(GroupNumber)
       'apply styling here
       cs.Color(0xFF03FFFF)
       cs.Link(m.Group(GroupNumber))
       cs.Append(m.Group(GroupNumber))
       cs.Pop.Pop 'number should match number of stylings set.
   Loop
   If lastMatchEnd < Input.Length Then cs.Append(Input.SubString(lastMatchEnd))
   Return cs
End Sub

Example for detect hashtag:
Label1.AttributedText = MarkPatternCSbuilder(Label1.Text,"\B(#\w+)\b",1)
 
Top