Remove Carriage Returns

S

Simon Harris

Hi All,

I am trying to write a function that will remove all carriage returns from
a
string, so that the string of words can be used as meta keywords.

So far I have:

Function RemoveCR(strText)
strText = Replace(strText,chr(13),"")
strText = Replace(strText,chr(10),"")
strText = Replace(strText,vbCrLf ,"VISUALBASIC")
RemoveCR = strText
End Function

My string still ends up with carriage returns in it though! I don't get
it,
what did I miss?

Thanks,
Simon.
 
K

Kyle Peterson

well, that looks pretty good really at 1st glance but it must be missing
something ?


I usually just do this in my own code when I log inot ot a text file and it
usually gets everything for me
You might want to try checking to 3 things my function looks for

The reason why I have a fix part is because I sometimes have many scenarios
in my function and this way I can have one function that can do a bunch of
things


Function FixStr(StrToFix,FixHow)

If Not IsNull(StrToFix) and StrToFix <> "" Then

If FixHow = "PrepareForLogfile" then
StrToFix = Replace(StrToFix,vbCrLf," ")
StrToFix = Replace(StrToFix,vbLf," ")
StrToFix = Replace(StrToFix,vbNewLine," ")
End If

End If

FixStr = StrToFix
End function



FixStr(Request("address_street"),"PrepareForLogfile")
 
B

Bob Barrows [MVP]

Simon said:
Hi All,

I am trying to write a function that will remove all carriage returns
from a
string, so that the string of words can be used as meta keywords.

So far I have:

Function RemoveCR(strText)
strText = Replace(strText,chr(13),"")
strText = Replace(strText,chr(10),"")
strText = Replace(strText,vbCrLf ,"VISUALBASIC")
RemoveCR = strText
End Function

My string still ends up with carriage returns in it though! I don't
get it,
what did I miss?

The first two lines are overkill. In fact, they will prevent the third line
from doing anything. vbCrLf is a constant that is equivalent to chr(13) &
chr(10).

I guess we need to see strText in order to see what is wrong. Are you sure
it does not contain html? Particularly "<BR>"?

Bob Barrows
 
S

Simon Harris

Hi,

Many thanks for the replies.

Seems I was calling my function incorrectly, or at the wrong time.

Simon.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top