Solved

strip characters

Posted on 1998-08-31
8
292 Views
Last Modified: 2013-12-03
A file is open as Random.  I need to look at a field and strip the alphas out so all I have left are numerics.  I have created a user defined type, and can get to the field this way.  I am at a loss as to how to get the program to read one character at a time and get rid of the letters.  
0
Comment
Question by:LJ083198
[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
8 Comments
 
LVL 9

Expert Comment

by:cymbolic
ID: 1432102
see the following
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1432103
A subroutine that will translate out any character and replace it with any other character string:

Public Function SubTran$(Inst$, lookfor$, ByVal Change2$)
 Dim i, j As Integer
 Dim InString$
 InString$ = Inst$
 j = 1
 i = InStr(j, InString$, lookfor$)
 While i > 0
   InString$ = Left$(InString$, i - 1) + Change2$ + Mid$(InString$, i + Len(lookfor$))
   j = i + Len(Change2$)
   i = InStr(j, InString$, lookfor$)
 Wend
 SubTran$ = InString$
End Function
0
 
LVL 2

Expert Comment

by:sbmc
ID: 1432104
fld=field
result=""
for i=1 to len(fld)
  ch=asc(mid(fld,i,1))
  if ch >= 48 and ch <= 57 then result=result & chr$(ch)
next i


Result should ony contain numerics after this routine.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 9

Expert Comment

by:cymbolic
ID: 1432105
A vb version of the translate instruction:

Public Trn$
'somewhere do once up front (form load? read from file?)
'set up translate table
dim i as integer
trn$=space$(256)  'default to spaces when not a number
for i=48 to 57  'Ascii 0 to Ascii 9
 mid$(trn$,i,1)=chr$(i)
next i

'then to translate
x.fld=xlt$(x.fld)

'then a subroutine
public function xlt$(instr$)
dim x$
dim i as integer
x$=space$(len(instr$))
for i =1 to len(x$)
 mid$(x$,i,1)=mid$(trn$,asc(mid$(instr$,i,1)),1)
next i
xlt$=x$
end function
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1432106
or, what sbmc sez, cause he typed it in before I got around to it, but that was next, but only if you want to just concatenate all numerics together.  The key is knowing where in the Ascii range of 0 to 255 the number characters fall.  

On a vb functional basis, there is always the IsNumeric function, but that carries a load of code around to check for numeric in an entire string.
0
 

Author Comment

by:LJ083198
ID: 1432107
It is not that this answer is unsatisfactory, I just used the solution provided by sbmc.  It seemed much more straightforward, and it worked. As far as sbmc answer goes, I thought it was an A.
0
 
LVL 2

Expert Comment

by:dabellei
ID: 1432108
There's also some function API that you can use wich are isalpha()  and isnumeric()  if you need more info let me know about it.
0
 

Accepted Solution

by:
vijayraj earned 50 total points
ID: 1432109

Dear LJ
          This best  method would be to read the entire file into a string .

In the first parse of string if ascii value of the character is less than 48 or its freater than 57 then at that substitute the character by space.

In the second parse read the string and if character is not space then write it into the same file and save it. That should give you the result


If you have any doubts email to me at vijay_raj_b@hotmail.com
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

752 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