Solved

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

Posted on 2004-10-03
3
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Introduction to Processes
Starting up a Project

724 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