Solved

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

Posted on 2004-08-09
5
630 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
[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
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
DarkoLord earned 70 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 30 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 2 hours left to enroll

622 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