SitePoint Sponsor |
|
User Tag List
Results 1 to 11 of 11
-
Apr 14, 2011, 09:08 #1
- Join Date
- Apr 2011
- Location
- Albany, NY
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ASP replace word special chars in string variables
Monthly I receive a calendar of events for posting on 2 web sites.(word document)
1. I open the word doc and paste the events into the first site (SharePoint site)
2. I then export the sharepoint calendar into an access DB
3. I then use classic ASP to take the events out of the export DB and
add them to the live DB on the second site.
Here’s where I run into problems:
When I extract the events from the export DB into ASP string variables, I need to find word special chars such as smart quotes and replace them with regular quotes. This is because if I leave them, they display on the web as a small square (unrecognized character).
I have tried the following code to replace the special chars:
titleeNew = replace(titleeNew, "“", """")
titleeNew = replace(titleeNew, "”", """")
titleeNew = replace(titleeNew, "'", "'")
titleeNew = replace(titleeNew, "’", "'")
Unfortunately the special characters I’m looking to replace are not being found in my string variable. I even tried the inSTR function to see if the special characters exist in the string and get back position 0, which means that even though the special chars are in the export DB, when I query them from the DB, somehow they are not ending up in the string variable.
What can I do?
-
Apr 14, 2011, 12:24 #2
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Can you try Paste-Special and use unformatted text into the SharePoint site?
Another thing to try is to paste some text (with the special chars) into a test string in an ASP page, then loop through each character and return it's ASC value. Example:
Code ASP:<% str = "This “is some text” with special chars" For i = 1 to Len(str) char = Mid (str,i,1) ascval = Asc(char) Response.Write "Character '" & char & "' has ASC value " & ascval & "<br>" Next %>
Code ASP:titleeNew = replace(titleeNew, Chr(147), """") titleeNew = replace(titleeNew, Chr(148), """")
-
Apr 14, 2011, 12:30 #3
- Join Date
- Apr 2011
- Location
- Albany, NY
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That's not exactly what I want to do. The reason I say that is that I actually want to replace characters like smart quotes and smart apostrophy with regular qoutes and regular apostrophy. I don't think I can find and replace in word. My thought was to import word to sharepoint and export to access. I would then find and replace in ASP as I import to other site.
Mostly I'm trying to do this with as few steps as possible. That way if the boss has to post the calendar one month, it will be easy for her to do.
Mike
-
Apr 14, 2011, 12:35 #4
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
You may have misunderstood what I was saying (or missed my edit).
Using the mechanism I show you'll be able to determine the special characters and their Asc codes, so will be able to replace the Chr coded characters with the normal characters you want, and have this already built in to your ASP script.
-
Apr 14, 2011, 12:37 #5
- Join Date
- Apr 2011
- Location
- Albany, NY
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok. i did miss your edit...
I can lookup the char codes and use those. maybe my copying the special char from word directly into my ASP code does not work. thanks
-
Apr 14, 2011, 22:35 #6
I now use Regular Express to replace any values from a string as for some reason I found it working more efficiently then the 'Replace' function. Below is the code I use, you can change it according to your req.
Code ASP:Private function fChr(byVal sfield) Set objRegExp = New RegExp objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.Pattern = " & " sfield = objRegExp.replace(sfield, " & ") objRegExp.Pattern = Chr(34) sfield = objRegExp.replace(sfield, """) objRegExp.Pattern = Chr(13) sfield = objRegExp.replace(sfield, " ") objRegExp.Pattern = "<br>" sfield = objRegExp.replace(sfield, " ") for A = 158 to 255 objRegExp.Pattern = Chr(A) sfield = objRegExp.replace(sfield, "&#"&A&";") next Set objRegExp = nothing fChr = sfield end function
-
Apr 15, 2011, 05:43 #7
- Join Date
- Apr 2011
- Location
- Albany, NY
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks ITHighway... you've saved the day and made my morning. now I just need to find the chr() value of all the characters I need to replace and all will be well.
-
Apr 15, 2011, 07:10 #8
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Which is where my original example post comes in. Just paste a copy of text that contains the characters into str and run the page - you'll get the Asc values (hence required Chr codes) for each character.
-
Apr 19, 2011, 12:09 #9
- Join Date
- Apr 2011
- Location
- Albany, NY
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Function fixit(strText)
strText = replace(strText, chr(147), """")
strText = replace(strText, chr(148), """")
'strText = replace(strText, """", """)
strText = replace(strText, chr(145), "'")
strText = replace(strText, chr(146), "'")
strText = replace(strText, chr(39), "'")
fixit = strText
end Function
when I call the function, fixit(titlee), no replace occurs. I can't see why. now the smart quotes are not getting replaced with regular quotes.
I've checked the ascii table and 147 & 148 are the correct values for the chr function.
what am I missing? the weird thing is that the code was working fine on Friday.
-
Apr 19, 2011, 12:59 #10
- Join Date
- Apr 2011
- Location
- Albany, NY
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
to confuse things further...
I added a few more replace statements to try and get the replace to occur:
strText = replace(strText, "“", """")
strText = replace(strText, "”", """")
strText = replace(strText, "’", "'")
strText = replace(strText, "‘", "'")
This seemed to get the conversion to occur. I did test it on a dummy page and was it work finally. Hen I put those extra lines of code in my original page, I get inconsistant results based upon when I view the file. it's as though sometimes the conversion occurs and sometimes it doesn't. can this be a bug with IIS in windows 7?
Mike
-
Apr 19, 2011, 13:25 #11
- Join Date
- Apr 2011
- Location
- Albany, NY
- Posts
- 26
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I just noticed that I was not calling the replace function in my code. I don't know why but adding the function call solved things. Also a smack palm to forehead helped.
Bookmarks