Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to recognize non-English characters in a string in VBScript

Posted on 2004-08-09
5
Medium Priority
?
652 Views
Last Modified: 2012-05-05
I have a VBScript to read lines of text from another file. Due to the nature of how the other file is produced, it contains some weird characters among other useable English words.

I want to read a line, analyze each character and get rid of any non-English or numeric characters and then write the text to another file.

Right now I am thinking to convert the string to an array then analyze each element of the array to see if it is any English letter or number. If so keep it else discard it. But I am not sure how to do it.

In C++, I remember, I could convert the character to Int and that Int will be the ASCII value of that character. But it won't let me do this in VBScript. So please help me out here.

Thanks!

BTW, if you could provide an even easier method to get rid of non-English and non-numeric characters from a string of text for VB Script, it would be even better.
0
Comment
Question by:UltimateApocalypse
  • 2
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 280 total points
ID: 11762022
Hi,

A-Z = 65-90
a-z = 97-122
.-, = 44-46

assuming you have text file stored in variable strData, the code would be something like this:

Dim i
For i = 0 To 255
    If Not (64 <= i And i <= 90) And Not (97 <= i And i <= 122) And Not (44 <= i And i <= 46) And i <> vbCrLf And i <> 32 Then
        strdata = Replace(strdata, Chr(i), "")
    End If
Next

Wscript.Echo strData
0
 
LVL 19

Assisted Solution

by:Shauli
Shauli earned 120 total points
ID: 11762468
'Something like that would get rid of all "non-enlish non-numeric" unwanted characters.
'the group of characters you do want are between 32(spca) and 122(z):

For c = 0 To 31
    myLine = Replace(myLine, Chr(c), "")
Next
For c = 123 To 255
    myLine = Replace(myLine, Chr(c), "")
Next
MsgBox myLine

S
0
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11762520
Yeah well thats same as my code except that my allows only "A-z", ",.-", " ", clrf :))

Darko
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11762562
DarkoLord , you are absolutely right. I just extended your approach to include characters like space, dash, colon etc..   :)

S
0
 

Author Comment

by:UltimateApocalypse
ID: 11763596
Thanks for the help, so the keyword here is Chr.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

971 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