Solved

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

Posted on 2004-10-03
3
350 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
canBalance challenge 34 65
squareUp  challenge 22 104
array6 challenfge 6 62
How  do I get an older program to run in Windows 10? 20 79
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 …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now