Re: text manipulation in a script?
Re: text manipulation in a script?
- Subject: Re: text manipulation in a script?
- From: email@hidden
- Date: Mon, 16 Sep 2002 12:02:09 EDT
John,
If this sort of thing weren't possible it would be a dark world indeed, IMHO.
Be careful with your terms - you as the programmer define the variables (in
AppleScript anyway, YMMV with othr languages). You may allow the user to set
the value that those variables have via user interface elements. "left,
right, up, down" is not a variable - it is a string, and a variable
(actually, its value or contents) may be set to that string. That value may
then be manipulated (that's why it's called a VARY-ABLE) thru any of a myriad
of useful techniques.
set userVar to text returned of (display dialog "Type something." default
answer "left, right, up, down")
log userVar
--> "left, right, up, down"
set userVar to userVar & ", in, out"
log userVar
--> "left, right, up, down, in, out"
set userVar to (text 1 thru 13 of userVar) & (text -7 thru -1 of userVar)
log userVar
--> "left, right, in, out"
set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set tempList to text items of userVar as list
set AppleScript's text item delimiters to " -"
set userVar to tempList as text
set AppleScript's text item delimiters to old_delims
log userVar
--> "left - right - in - out"
Please, please, please don't tell us you've been doing *all* your text
manipulations by writing to files and telling other applications to do the
manipulations for you! How completely restricting and generally unnecessary.
Jeff Baumann
email@hidden
www.linkedresources.com
cc please, on digest
In a message dated 9/14/02 6:08:42 PM, John Kinsella writes:
<BLOCKQUOTE CITE STYLE="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px;
MARGIN-RIGHT: 0px; PADDING-LEFT: 5px"> Can I manipulate a user defined
variable (much like I would manipulate text
>
in a document. What I mean is, if a user gives me a variable like "left,
>
right, up, down" can I manipulate that an set it as a new variable for use
>
later in the script. In this example, maybe I'd manipulate it by taking
>
this variable, converting all the comma's to "-" and setting a new variable
>
of "left - right - up - down"
>
Now, I know I could write the user variable to a file, manipulate it and
>
then copy the result to a new variable, but I'm hoping this might be
>
possible without that step, just be able to do simple replaces within the
>
script
>
I'm not sure if I can even do this, so I thought I'd ask before I spent
>
hours on it.
>
Ideas? Suggestions?
>
John Kinsella
>
IRT-CS
>
University of St. Thomas
>
-------------
>
"The surest way to corrupt a youth is to teach him to hold in higher regard
>
those who think alike rather than those who think differently."
>
--Nietzsche
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.