Solved

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

Posted on 2004-10-03
3
361 Views
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:

----------------------------------------------------------------
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
Comment
Question by:kcs_tec
  • 2
3 Comments
 

Author Comment

by:kcs_tec
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:
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
 
LVL 13

Accepted Solution

by:
davidlars99 earned 400 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)
     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
 

Author Comment

by:kcs_tec
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!

Cheers.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 125
ejb message driven bean mdb creation steps 2 34
Do Wend Macro not working 22 56
WordPress: Debugging from my Windows 10 Desktop 6 61
A short article about a problem I had getting the GPS LocationListener working.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 …

685 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