• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

web-based VB comparison of English and cyrillic strings in unicode

Please help me someone..

Need to do a strong comparison in VB for two words - first is an english word and second is a russian word in Cyrillic.

I'm getting the vocab list from a basic text file which is in unicode
format (I think). An example of the text file is here:

----------------------------------------------------------------
above
над
accident
авария
accomodation
жилье
----------------------------------------------------------------

First is english word, then CR then russian word and so on.

The web-page displayes an English or Russian word and the
user must type the translated equivalent into a form field which
is then sent to another ASP file for checking to see if it's correct.

The system works fine if the user types an english answer word and I
just need to compare that english word with the one in the text file.
But if it's vice versa and I must compare an inputted russian word
with one in the text file then it doesn't work. Probably because it's
trying to compare real ASCII russian with those damn unicode strings.

Can anyone suggest a way of either forcing the webpage to convert
the inputted string to unicode or altlernatively converting the unicode
text file (or original XLS file) into real russian ascii characters.

Thankyou!

0
kcs_tec
Asked:
kcs_tec
  • 2
1 Solution
 
kcs_tecAuthor Commented:
I forgot, in case it is useful you can see some of the ASP code from
the file I'm using to calculate if the answer was correct (I know it's
real messy but it's only a test version and I haven't time to document
it yet).  also you can see a sort of working example of it at:
http://www.aquerius.co.uk/russian/vocab.asp
(it's only the version that compares an english answer with an english
text file word. For the non-working version that does it vice-versa you
can visit: http://www.aquerius.co.uk/russian/vocab2.asp

----------------------------------------------------------------------------------
    Dim voce(900)
    Dim vocr(900)
    dim wordnum,numwords
    Dim fso, f, txtStream
    Dim fileName, strText

    fileName = Server.Mappath("vocab.txt")
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFile(fileName)
    Set txtStream = f.OpenAsTextStream(openForReading)
    numwords=0
    Do While Not txtStream.AtEndOfStream
        voce(numwords) = txtStream.ReadLine
        vocr(numwords) = txtStream.ReadLine
        numwords=numwords+1
    Loop
    txtStream.Close
    Set txtStream = Nothing
    Set f = Nothing
    Set fso = Nothing

wordnum=Request.QueryString("wordnum_v")
answer2=Request.form("answer_v")
answer2=lcase(answer2)
 
    l = len(answer2)
    redim array_q(l-1)
    For i = 0 To l-1
      array_q(i) = mid(answer2,i+1,1)
    next

    if len(voce(wordnum))>l then l=len(voce(wordnum))
    For i = 0 To l-1
      if (i<=ubound(array_q)) and (i<=len(voce(wordnum))) then
        if array_q(i)=mid(voce(wordnum),i+1,1) then score_sub=score_sub+1
      end if
    next
---------------------------------------------------------------------------------
0
 
davidlars99Commented:
and here what you asked for. this functions will replace "Unicode with ASCII" and backwords

<%
Function UnicodeToAscii(ByRef pstrUnicode)
     Dim llngLength
     Dim llngIndex
     Dim llngAscii
     Dim lstrAscii
         
     llngLength = Len(pstrUnicode)
         
     For llngIndex = 1 To llngLength
          llngAscii = Asc(Mid(pstrUnicode, llngIndex, 1))
          lstrAscii = lstrUnicode & ChrB(llngAscii)
     Next
         
     UnicodeToAscii = lstrAscii
End Function


Function AsciiToUnicode(ByRef pstrAscii)
         
     Dim llngLength
     Dim llngIndex
     Dim llngAscii
     Dim lstrUnicode
         
     llngLength = LenB(pstrAscii)
         
     For llngIndex = 1 To llngLength
          llngAscii = AscB(MidB(pstrAscii, llngIndex, 1))
          lstrUnicode = lstrUnicode & Chr(llngAscii)
     Next
         
     AsciiToUnicode = lstrUnicode
         
End Function

Dim sUnicodeValue, sAsciiValue
sUnicodeValue = request.querystring("your_word")
sAsciiValue = UnicodeToAscii(sUnicodeValue)
Response.Write "Unicode = " & sUnicodeValue & "<br>"
Response.Write "ASCII = " & sAsciiValue & "<br>"
Response.Write "<br>Unicode = " & AsciiToUnicode(sAsciiValue) & "<br>"
%>
0
 
kcs_tecAuthor Commented:
Hi there,

thanks very much for the detailed code sample and comments, its
much appreciated.

Unfortunately despite spending over an hour on it, I couldn't get
your code to convert either from ascii to unicode or vice versa.

I also tried changing the web codepage settings but to no avail.

Anyway the good news is that I tried fixing the problem from
another angle and everything is working perfectly now. I simply
downloaded a good hex editor and pasted the russian words
directly from Excel into the hex editor and then saved it as an
ANSI/ASCII file in hex format instead of relying on Word or notepad
which would only save in unicode.

The whole thing works fine now without those stupid unicodes. Wish
that word would have saved it in ANSI/ASCII in the first place!

I'm giving davidlars99  the points anyway because he at least
bothered to try and give me a solution!

Cheers.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now