• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reformatting a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reformatting a string


  • Subject: Re: Reformatting a string
  • From: Roadrunner Angelo <email@hidden>
  • Date: Fri, 27 Jan 2012 15:36:17 -0600

Thanks for all your help.    You guys are awesome.

AG



> I need to take a long string string of letters numbers and colons and convert it to uppercase letters w/ no colons.
> a2:fh:2f:vv:i1:q1   needs to be  A2FH2FVVI1Q1.  (the string is normally longer that this example)
>
> I currently slap it into a new Mail document and “Transform” to uppercase and then “Find” the colons and replace with nothing.   That works OK,
> but I know it’s archaic and one of you guys could craft a script in a few minutes that would take me a few hours to create.  I was thinking along the lines of a dialog box where I pasted the raw string and it produced a message box with the reformatted version, but anything would be helpful.   Is it possible to copy the string and then do the reformatting to the contents of the Clipboard so that I can just copy -> run script -> paste where it needs to go?

Try this ...

on run
	set originalText to (get the clipboard)
	set newText to my transformedText(originalText)
	set the clipboard to newText
end run

on transformedText(orgText)
	set newStr to ""
	repeat with i from 1 to (length of orgText)
		set charID to (id of character i of orgText)
		if 48 ≤ charID and charID ≤ 57 then -- digit
			set newStr to (newStr & (character id charID))
		else if 65 ≤ charID and charID ≤ 90 then -- upper
			set newStr to (newStr & (character id charID))
		else if 97 ≤ charID and charID ≤ 122 then -- lower
			set charID to (charID - 32)
			set newStr to (newStr & (character id charID))
		end if
	end repeat
	return newStr
end transformedText

In AppleScript Editor, save as an application. For best results, put its icon in the dock or use the Script Menu.
If you double-click its icon in the Finder, you have to click again to activate the original application.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


References: 
 >Reformatting a string (From: Angelo <email@hidden>)
 >Re: Reformatting a string (From: Luther Fuller <email@hidden>)

  • Prev by Date: Re: Reformatting a string
  • Next by Date: Re: Reformatting a string
  • Previous by thread: Re: Reformatting a string
  • Next by thread: Re: Reformatting a string
  • Index(es):
    • Date
    • Thread