r/applescript • u/Mapinact • Apr 01 '22
Trying and failing to strip \ from a string
I have a variable auctiondate as text that I'm stripping from a web page. The text returned looks like this
Auction 04\u002F23\u002F22I'm trying and failing to strip the \u002F (a UTF16 encoding for /) and replacing it with / so that the final text looks like
Auction 04/23/22I'm trying to use a shell script snippet to do this.
set auctiondate to do shell script "sed 's|" & quoted form of "\\u002F" & "|" & quoted form of "/" & "|g' <<< " & quoted form of auctiondatebut what I get back is
Auction 23\\/04\\/22It's happily replacing the u002F part of the string but not touching the \\ part of the string. What do I need to do to get rid of the \\??
EDIT: Fixed text in first sample
3
Upvotes
1
u/sargonian Apr 01 '22
Another way to do it without a shell script is using text item delimiters. Here's a handy function to keep around for replacing strings.
1
u/ChristoferK Apr 13 '22
The simplest way would be to take the text you get returned, and execute it as a JXA script:
1
u/[deleted] Apr 01 '22
[removed] — view removed comment