Public Sub htmlProcessor(ByVal html As String)
'amade sazi matn ghabl az hame
Select Case SourceLang
Case "Farsi"
NewHtml = Replace(NewHtml, "ی", "ی")
NewHtml = Replace(NewHtml, "ک", "ک")
End Select
Dim start As Integer
Dim length As Integer
Dim newcode As String
'find body location
'========================
BodyStart = InStr(1, html, "<body", CompareMethod.Text)
BodyFinish = InStr(1, html, "</body>", CompareMethod.Text) + 6
Body = Mid(html, BodyStart, BodyFinish - BodyStart + 1)
'========================
NewHead = Mid(html, 1, BodyStart - 1)
NewBody = Body
'========================
i = 1
Do
TagStart = InStr(i, NewBody, "<")
TagFinish = InStr(i, NewBody, ">")
Select Case TagStart - TagFinish
Case 1 ' Body=" ><i...."
i = TagStart + 1
Case Is > 0 ' Body=" >matin<i ......"
start = TagFinish + 1
length = TagStart - TagFinish - 1
newcode = NewCodeGenerator(Mid(NewBody, start, length))
NewBody = Mid(NewBody, 1, start - 1) & newcode & Mid(NewBody, start + length)
i = start + Len(newcode) + 2
Case 1 - TagFinish ' Body="< >matin<i..."
TagStart = InStr(TagFinish, NewBody, "<")
start = TagFinish + 1
length = TagStart - TagFinish - 1
newcode = NewCodeGenerator(Mid(NewBody, start, length))
NewBody = Mid(NewBody, 1, start - 1) & newcode & Mid(NewBody, start + length)
i = start + Len(newcode) + 1
Case Is < 0 ' Body="i >"
i = TagFinish + 1
End Select
TagStart = 0
TagFinish = 0
Loop Until i > Len(NewBody)
NewHtml = NewHead & NewBody
End Sub
Public Function NewCodeGenerator(ByVal txt As String) As String
txt = Replace(txt, "0", "۰")
txt = Replace(txt, "1", "۱")
txt = Replace(txt, "2", "۲")
txt = Replace(txt, "3", "۳")
txt = Replace(txt, "4", "۴")
txt = Replace(txt, "5", "۵")
txt = Replace(txt, "6", "۶")
txt = Replace(txt, "7", "۷")
txt = Replace(txt, "8", "۸")
txt = Replace(txt, "9", "۹")
txt = Replace(txt, "!", " ! ")
txt = Replace(txt, "؟", " ؟ ")
txt = Replace(txt, ".", " . ")
txt = Replace(txt, "،", " ، ")
txt = Replace(txt, ":", " : ")
txt = Replace(txt, "(", "( ")
txt = Replace(txt, ")", " )")
txt = CompleteTrim(txt)
Dim NCd As String
Dim WordArr() As String
WordArr = Split(txt)
If first = False Then
idx = 0
ReDim words(1, UBound(WordArr))
first = True
Else
ReDim Preserve words(1, idx + WordArr.GetUpperBound(0))
End If
For i = 0 To WordArr.GetUpperBound(0)
words(0, i + idx) = WordArr(i)
NCd = NCd & "<X>" & i + idx & "</X>"
Next
idx = idx + WordArr.GetUpperBound(0) + 1
Return NCd
End Function