473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

passing a string in Cyrillic

PhilOfWalton
1,430 Expert 1GB
I have a Russian word близко (close) and I want to check that the word is indeed in Cyrillic script

Now I know that the Unicode range for Cyrillic is 0400 to 04FF and the Cyrillic supplementary is from 0500 to 052F

In windows I have added Russian as a language pack, and in Access changed the editor format to Arial (Cyrillic)

I can copy the Cyrillic word into my table OK.

If I try to pass the word so a function to try to attempt some verification, the word appears as ??????. and obviously I can do nothing with it.

Any ideas how to pass words in non Latin languages

Thanks

Phil
Sep 13 '17 #1

✓ answered by Rabbit

Hmm, interesting. You have to use StrConv to convert it to Unicode first.

Expand|Select|Wrap|Line Numbers
  1. Sub Test()
  2.     Dim str As String, i As Integer
  3.     str = StrConv(DLookup("Field1", "Table2"), vbUnicode)
  4.     For i = 1 To Len(str) Step 2
  5.         Debug.Print Right("0" & Hex(Asc(Mid(str, i + 1, 1))), 2) & Right("0" & Hex(Asc(Mid(str, i, 1))), 2)
  6.     Next
  7. End Sub
Which prints this when run against the string you supplied above.
Expand|Select|Wrap|Line Numbers
  1. 0431
  2. 043B
  3. 0438
  4. 0437
  5. 043A
  6. 043E

6 4542
Rabbit
12,516 Expert Mod 8TB
Hmm, interesting. You have to use StrConv to convert it to Unicode first.

Expand|Select|Wrap|Line Numbers
  1. Sub Test()
  2.     Dim str As String, i As Integer
  3.     str = StrConv(DLookup("Field1", "Table2"), vbUnicode)
  4.     For i = 1 To Len(str) Step 2
  5.         Debug.Print Right("0" & Hex(Asc(Mid(str, i + 1, 1))), 2) & Right("0" & Hex(Asc(Mid(str, i, 1))), 2)
  6.     Next
  7. End Sub
Which prints this when run against the string you supplied above.
Expand|Select|Wrap|Line Numbers
  1. 0431
  2. 043B
  3. 0438
  4. 0437
  5. 043A
  6. 043E
Sep 13 '17 #2
PhilOfWalton
1,430 Expert 1GB
Thank a lot Rabbit, we're there!

Slight change of code, but I am passing this back in case you're interested

I have a table of languages that holds the Unicode language range which I pass to the function:
Expand|Select|Wrap|Line Numbers
  1. Function CheckLanguageOK(Word As String, LanguageLegalFrom As Long, LanguageLegalTo As Long) As Boolean
  2.  
  3.     Dim UnicodeChar As String
  4.     Dim UnicodeValue As Long
  5.     Dim i As Integer
  6.     Dim TestWord As String
  7.  
  8.     If LanguageLegalFrom = 0 Or LanguageLegalTo = 0 Then     ' Language not foun
  9.         Exit Function
  10.     End If
  11.  
  12.     TestWord = StrConv(Word, vbUnicode)
  13.     CheckLanguageOK = -1
  14.  
  15.     For i = 1 To Len(TestWord) Step 2
  16.         UnicodeChar = Right("0" & Hex(Asc(Mid(TestWord, i + 1, 1))), 2) & Right("0" & Hex(Asc(Mid(TestWord, i, 1))), 2)
  17.         UnicodeValue = Val(UnicodeChar)
  18.  
  19.         If ChangeHexToDecimal("&h" & UnicodeChar) < Val(LanguageLegalFrom) Or ChangeHexToDecimal("&h" & UnicodeChar) > Val(LanguageLegalTo) Then
  20.             CheckLanguageOK = 0
  21.             Exit For
  22.         End If
  23.     Next i
  24.  
  25. End Function
  26.  
Works perfectly

Thanks again
Sep 13 '17 #3
PhilOfWalton
1,430 Expert 1GB
Sorry, a supplementary question.
I have the following series of bytes, those beginning with 04 are Cyrillic, and those beginning with 00 are English.

Expand|Select|Wrap|Line Numbers
  1. 0435
  2. 0020
  3. 0434
  4. 0430
  5. 043D
  6. 043D
  7. 044B
  8. 0435
  9. 003C
  10. 002F
  11. 0073
  12. 0070
  13. 0061
  14. 006E
  15.  
At some point I need to strip the English stuff off and just leave the Cyrillic.
How do I convert those numbers to Unicode so that they can be read as a word?

Again thanks

Phil
Sep 14 '17 #4
PhilOfWalton
1,430 Expert 1GB
Not to worry. Problem solved

Phil
Sep 14 '17 #5
Rabbit
12,516 Expert Mod 8TB
Cool, just curious, what did you have to do to get it back into the table?
Sep 14 '17 #6
PhilOfWalton
1,430 Expert 1GB
Hi Rabbit

The guts of the solution is below

The first bit of code is abbreviated but essentially it is translating an Input string to an Output String using say German as the input language an French as the output language

The translation line would look like this
Expand|Select|Wrap|Line Numbers
  1. IE.Navigate "http://translate.google.com/#" & "de" & "/" & "fr" & "/" & "Cat"
  2.  
Here is part of the code
Expand|Select|Wrap|Line Numbers
  1.  Translate2_Start:
  2.     Set IE = CreateObject("InternetExplorer.Application")
  3.     IE.Visible = 0
  4.  
  5.     ' TO CHOOSE INPUT LANGUAGE
  6.     If Nz(InLanguage) = "" Then
  7.         InLanguage = "auto"
  8.     End If
  9.  
  10.     'Open website
  11.     IE.Navigate "http://translate.google.com/#" & InLanguage & "/" & OutLanguage & "/" & InputStr
  12.  
  13.     DoEvents
  14.  
  15.     Do Until IE.ReadyState = 4
  16.         apWait LanguageTranslateTime, 0                         ' Wait half .05 seconds
  17.         DoEvents
  18.     Loop
  19.  
  20.     OutputStr = Replace(IE.Document.getElementById("result_box").innerHTML, "<span>", "")   ' Get rid of the HTML "<span>"
  21.  
  22.     IE.Quit
  23.  
  24.      If OutputStr > "" Then
  25.         OutputStr = Replace(OutputStr, "</span>", "")           ' Get rid of the HTML "</span>"
  26.         OutputStr = Replace(OutputStr, "&amp;", "&")            ' Replace undescored shortcut letters
  27.  
  28.        TranslatedWord = StrConv(OutputStr, vbUnicode)
  29.         TestWord = ""
  30.         For i = 1 To Len(TranslatedWord) Step 2
  31.             Debug.Print Right("0" & Hex(Asc(Mid(TranslatedWord, i + 1, 1))), 2) & Right("0" & Hex(Asc(Mid(TranslatedWord, i, 1))), 2)
  32.             TestWord = Right("0" & Hex(Asc(Mid(TranslatedWord, i + 1, 1))), 2) & Right("0" & Hex(Asc(Mid(TranslatedWord, i, 1))), 2)
  33.             TmpWord = TmpWord & CharW("U" & TestWord, -1)        ' Indicate it's a unicoode character
  34.         Next i
  35.  
  36.             Debug.Print StrConv(OutputStr, vbUnicode)
  37.     End If
  38.  
The second function uses the ChrW$ function to return each 4 digit hex number as a Cyrillic letter (providing you have the Russian Language pack installed?????)

I add the ???? because I can translate into Mongolian (well someone has to) and I don't have the Mongolian language pack installed.
In fact I have just added Bengali as a language, to translate to, but have not added the language pack, and it is coming out OK.

Interesting!

Expand|Select|Wrap|Line Numbers
  1. Public Function CharW(TestWord As Variant, Optional Exact_functionality As Boolean = False) As String
  2.     ' Use a Leading “U” or “u” to indicate Unicode values
  3.     ' Exact_functionality returns the Unicode characters for Ascii(128) to Ascii(159) rather than the Windows characters
  4.  
  5.     If UCase(Left$(TestWord, 1)) = "U" Then
  6.         TestWord = Replace(TestWord, "U", "&H", 1, 1, vbTextCompare)
  7.     End If
  8.  
  9.     TestWord = CLng(TestWord)
  10.  
  11.     If TestWord < 256 Then
  12.         If Exact_functionality Then
  13.             CharW = ChrW(TestWord)
  14.         Else
  15.             CharW = Chr(TestWord)
  16.         End If
  17.     Else
  18.         CharW = ChrW(TestWord)
  19.     End If
  20.  
  21. End Function
  22.  
Phil
Sep 15 '17 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Suddn | last post by:
Help me get my mind around passing string types to a function. I need to have the function modify the string types and get them back. Normaly I would just return the modified string but I need to...
2
by: o1j2m3 | last post by:
I created 2 forms, A and B using VB.NET 2003 in A, the codes are : ========================== public AsName as string public AsPrice as double public sub setValue(ByVal sname as string,...
1
by: muntyanu | last post by:
Hi all, I am passing string from C++ to C# but not sure which way is more correct. Here it is: First approach: CDAnetCSharpHooks::PassString( ) { char str = "String to pass"; DotNetObject...
1
by: Pontifex | last post by:
Hi all, Has anyone devised a simple method for passing a string to an external script? For instance, suppose I want to produce a title bar that is very fancy and I don't want my main HTML...
5
by: goldtech | last post by:
Hi, I'm passing what I think is a string parameter to another Python program (spawn.py) - see the code snip below. But only the counter part gets printed to a log file via spawn.py. Yet the...
2
by: pcaisse | last post by:
Could someone please tell me why this stupid script doesn't print the string being passed to the sub?: #!/usr/bin/perl -w use strict; print "Work, damnit!\n"; my $val = "print me";
14
by: Kerem Gümrükcü | last post by:
Hi, i want to emulate a (synchronous) BroadCastSystemMessage with EnumWindows and SendMessage. I dont want to use the BroadcastSystemMessage because it needs the SE_TCB_NAME Privilege (you...
3
by: Peeyush81 | last post by:
Hi, I have created a win32 dll with an exported method. extern "C" __declspec(dllexport) void LocateAddress(struct stLocateAddressParam arrAddressParam,int nClientType, LPTSTR outptr); In...
0
by: BobbyS | last post by:
I've a xml file.I'm taking its data passing it to a method in string form and converting that string "xmlData" to a array of bytes by Convert.FromBase64String(xmlData) but I'm getting a exception...
13
by: masso600 | last post by:
char word; in = fopen("test.txt", "r"); while(fscanf(in,"%s",&word)!=EOF) { /* Print all words */ /* printf("%s\n",&word); */
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.