Strings

C

Craig

On my earlier post, I want to make it clear that I am only
interested in eliminating characters that I SPECIFY!!!

In other words, I need this to be very much like a replace
function. I want to put a list of substrings and
characters in my program and the program will search every
string for these and, if found, will replace them
with "".

if anyone can help me, please contact me at
(e-mail address removed)

thank you
 
L

Leonard Selmani

I already replied to one of your 5 posts about the same
thing. Did you read it, or do a little research on it?
Look at the extract function and see if you can make it so
instead of extracting letters as it is doing, you can make
it extract any other character instead. Also if you want
to go the more *difficult* way try and look for *arrays*
in vba (http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/modcore/html/deconunderstandingarrays.asp)





------------------------------------------------------
What I'm thinking in your case, what
you might want to do is *extract* the characters that you
want from that string. If all you want are numbers and
letters of any case (upper or lower) then what you might
want to do is check what the ascii values are for letters
and numbers. example

Function fExtractStr(ByVal strInString As String) As String
Dim lngLen As Long, strOut As String
Dim i As Long, strTmp As String

lngLen = Len(strInString)
strOut = ""
For i = 1 To lngLen
strTmp = Left$(strInString, 1)
strInString = right$(strInString, lngLen - i)
'The next statement will extract BOTH Lower and Upper
case chars
If (Asc(strTmp) >= 65 And Asc(strTmp) <= 90) Or _
(Asc(strTmp) >= 97 And Asc(strTmp) <= 122) Then
'to extract just lower case, use the limit 97 -
122
'to extract just upper case, use the limit 65 -
90
strOut = strOut & strTmp
End If
Next i
fExtractStr = strOut
End Function

you can also accomplish the same thing by defining an array
() and inserting all the letters and numbers of the
alphabet in there, then grab your string and put it in a
loop and match each character from the string to that of
the array. Whenever a character from the string doesn't
match you get rid of it:

Replace(yourstringhere,charToReplace,"")

HTH
 
M

Marshall Barton

Craig said:
On my earlier post, I want to make it clear that I am only
interested in eliminating characters that I SPECIFY!!!

In other words, I need this to be very much like a replace
function. I want to put a list of substrings and
characters in my program and the program will search every
string for these and, if found, will replace them
with "".


You can use the Replace technique I posted in another one of
your threads.

For A97 (which doesn't have the Replace function), you can
use this function instead of Replace:

Function Subst(Original As Variant, Search As String, _
Replace As String) As Variant
Dim pos As Long

Subst = Original
If IsNull(Subst) Then Exit Function
If Len(Search) > 0 Then
pos = InStr(Subst, Search)
Do Until pos = 0
Subst = Left(Subst, pos - 1) & Replace _
& Mid$(Subst, pos + Len(Search))
pos = InStr(pos + Len(Replace), Subst, Search)
Loop
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top