i want to make in a applescript that will turn this: “Bob’s Food Rocks!” into “bobsfoodrocks”
i need this so that i can make a string like the one above work in a url
is there a way to do this?
thxs for the help!
i want to make in a applescript that will turn this: “Bob’s Food Rocks!” into “bobsfoodrocks”
i need this so that i can make a string like the one above work in a url
is there a way to do this?
thxs for the help!
You can manipulate text in Applescript. For example, get rid of the spaces by setting applescript’s text item delimitters to " ", then set URLvar to text items of theWords as string, etc.
But a far better choice would be to run the string through a URL encode function.
See hhas’s clever bit of python in http://bbs.applescript.net/viewtopic.php?id=13189
This should work if you only want lower case characters and numbers in the new text.
set oldString to "Bob's Food Rocks!"
set newString to ""
repeat with myChar in oldString
set myNum to ASCII number of myChar
if myNum is greater than 64 and myNum is less than 91 then set myNum to (myNum + 32)
if myNum is greater than 96 and myNum is less than 123 then set newString to newString & (ASCII character of myNum)
if myNum is greater than 47 and myNum is less than 58 then set newString to newString & (ASCII character of myNum)
end repeat
newString
Best wishes
John M
i downloaded this (the TextCommands thing) but i can’t figure out how to work it? anyone know? thxs
p.s. It’s not that i don’t like the methods above, i just want to understand what i use, and i think i might understand the thing above.
thxs!
John’s suggestion seems about as simple as can be. You should be able to figure it out what it does, and if not, feel free to ask questions.
What’s the problem with your textCommands code? Can you post it and tell us where you’re having the problem?
Sorry, i was a little vague… First i’ll start with my question about john’s script:
what do the numbers of ASCII characters mean?
EX, this part confuses me:
if myNum is greater than 64 and myNum is less than 91 then set myNum to (myNum + 32)
if myNum is greater than 96 and myNum is less than 123 then set newString to newString & (ASCII character of myNum)
if myNum is greater than 47 and myNum is less than 58 then set newString to newString & (ASCII character of myNum)
for the part about the textCommands thing, my question is:
How do you implement one of the commands such as “lowercase”?
everytime i tried i got a syntax error.
So, could someone show me how to make the textCommands work?
thxs for all your help!
ASCII (American Standard Code for Information Interchange) is a standard format for the numerical representation of a character. See http://www.lookuptables.com/ for an ASCII character table.
The script loops and gets the ASCII number associated with each character (myChar) in the string (oldString). If the number (myNum) is in the range for upper case letters (62-90) it adds 32 to shift it to the range for lower case letters. If myNum is now in the range of lower case letters (97-122) or numbers (48-57) it adds the associated character to the end of the variable newString. If the character is not a letter or a number it is not added to newString.
--If the letter is an upper case letter add 32 to ascii code to shift to lower case letters
if myNum is greater than 64 and myNum is less than 91 then set myNum to (myNum + 32)
--If it is a lower case letter or modified from upper case add to new string
if myNum is greater than 96 and myNum is less than 123 then set newString to newString & (ASCII character of myNum)
--If it's a number add to new string
if myNum is greater than 47 and myNum is less than 58 then set newString to newString & (ASCII character of myNum)
HTH
John M