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

Posted on 2004-10-03
Medium Priority
Last Modified: 2011-10-03
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:


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.


Question by:kcs_tec
  • 2

Author Comment

ID: 12210901
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:
(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)
    Do While Not txtStream.AtEndOfStream
        voce(numwords) = txtStream.ReadLine
        vocr(numwords) = txtStream.ReadLine
    Set txtStream = Nothing
    Set f = Nothing
    Set fso = Nothing

    l = len(answer2)
    redim array_q(l-1)
    For i = 0 To l-1
      array_q(i) = mid(answer2,i+1,1)

    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
LVL 13

Accepted Solution

davidlars99 earned 800 total points
ID: 12255540
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)
     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)
     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>"

Author Comment

ID: 12304064
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!


Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
AngularJS web development a very simple procedure. So, to put it, in short, AngularJS’ stand out features are – Two-way data binding, MVC structure, directives, templates, dependency injections and testing.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Loops Section Overview

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question