Global replace Function

Results 1 to 2 of 2

Thread: Global replace Function

  1. #1
    Join Date
    Dec 1969

    Default Global replace Function

    I recently came across this aspfaq#27 through a reply to my earlier mail about the above. I am trying to use this function to replace other ASCII characters like chr(13), chr(10),vbcrlf, etc.<BR><BR>My problem is how do I include this other characters in the replace function below:<BR><BR>Here is the function:<BR><BR>&#060;%<BR>&#039;**************** *****************************************<BR>Funct ion RemoveCharacters() <BR> dim frm,item <BR> Set frm = Server.CreateObject("Scripting.Dictionary") <BR> frm.CompareMode=1 <BR> item=("str1,str2,str3")<BR> myarray=Split(item,",")<BR> myarray_size=UBound(myarray)<BR> For each field in myarray<BR> frm.Add Cstr(field), Replace(field,"&#039;","&#039;&#039;") <BR> Next <BR> Set RemoveCharacters = frm <BR>End Function <BR>&#039;**************************************** *********<BR>%&#062;<BR><BR>I then wish to call this function on all my necessary asp pages, using this call routine<BR><BR>set myfuntion= RemoveCharacters()<BR><BR>mystring=myfunction(RS.f ields("myfield").value<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Global replace Function

    You need something similar to the code snippet you found but not as complex:<BR><BR>Function RemoveCharacters(strText)<BR> arrChars = array(vbCr, vbLf, vbCrLf)<BR> for i = 0 to ubound(arrChars)<BR> strText = replace(strText, arrChars(i), "")<BR> next<BR> RemoveCharacters = strText<BR>End Function<BR><BR>You can then call the function as you specified (not sure what you meant by the "set myfuntion= RemoveCharacters()" bit though).<BR>Any character(s) you specify in the comma separated list in the function (vbCr, vbLf, vbCrLf) will be removed from the resulting string.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts