Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Applescript > Re: headache.
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 1576 of 1647
Post > Topic >>

Re: headache.

by Jerry Kindall <jerrykindall@[EMAIL PROTECTED] > Feb 17, 2008 at 12:49 PM

In article <joshuafwhalen-6683F0.15181917022008@[EMAIL PROTECTED]
>,
Joshua Whalen <joshuafwhalen@[EMAIL PROTECTED]
> wrote:

> I'm trying to strip unwanted characters from some data. the first item 
> is a name or indeterminate elements. for example, "Frida Hyvonen" or 
> "Orchestral Maneuvers in the Dark". 
> 
> I want to end up with "FridaHyvonen" or "OrchestralManeuversintheDark". 
> So I have subroutine, the one below, and it does this part just fine.  
> When I repeat the same process to cleanse a date value in a similar way,

> for example to turn "Saturday, February 16, 2008 12:15:46 PM" into 
> "Saturday,February16,200812:15:46PM", that works.
> 
> BUT! if I then take "Saturday,February16,200812:15:46PM" and try to 
> strip the commas, I get:
> "Saturday February16 200812:15:46PM" which is not what I want. I want:
> "SaturdayFebruary16200812:15:46PM", and eventually, I want to get to:
> "SaturdayFebruary162008121546PM", but when I try to run the subroutine 
> again, to strip the spaces, I end up with:
> "Saturday,February16,200812:15:46PM"
> 
> The subroutine that should do all but the last operation is below. Any 
> idea why I keep getting either the commas or the spaces, no matter what 
> I do?
> 
> on ShaveMyFileName(MyFadeDate)
>    
>    set MyShaveItem to MyShowName as text
>    set this_text to MyShaveItem
>    set search_string to (ASCII character 32)
>    set replacement_string to {}
>    set MyFadeName to my replace_chars(this_text, search_string, 
> replacement_string)
>    display dialog MyFadeName
>    
>    set MyTrimTime to MyFadeDate as text
>    set this_text to MyTrimTime as string
>    set search_string to (ASCII character 32)
>    set replacement_string to (ASCII character 0)
>    set MyTrimTime to my replace_chars(this_text, search_string, 
> replacement_string)
>    display dialog MyTrimTime
>    
>    set MyTrimTime to MyFadeDate as text
>    set this_text to MyTrimTime
>    set search_string to (ASCII character 44)
>    set replacement_string to (ASCII character 0)
>    set MyTrimTime to my replace_chars(this_text, search_string, 
> replacement_string)
>    display dialog MyTrimTime
>    
>    set MyTrimTime to MyFadeDate as text
>    set this_text to MyTrimTime
>    set search_string to (ASCII character 32)
>    set replacement_string to (ASCII character 0)
>    set MyTrimTime to my replace_chars(this_text, search_string, 
> replacement_string)
>    display dialog MyTrimTime
>    
> end ShaveMyFileName

There is so much stuff there that it takes some effort to figure out
what you're trying to do.  All those unnecessary variables and
assignments!  And why are you using ASCII codes rather than just using
the characters?  (And why "ASCII character 0" rather than a null
string?)  (And what is "Fade" supposed to mean and how is it different
from "Shave" and "Trim"?  And why all the "my"?)

The real problem, aside from all the obfuscation, is that you are
removing the space characters in MyTrimTime, THROWING AWAY the result
of that operation (by replacing MyTrimTime, to which you have assigned
the result, with MyFadeDate again), then removing all the commas from
MyTrimTime, then THROWING THAT RESULT AWAY TOO in exactly the same way,
and then finally removing all the space characters from MyTrimTime a
second time, probably because it appears that removing the spaces put
the commas back in.  (Naturally, nothing of the sort has happened.)

Removing all the unnecessary variable assignments and fixing the
throwing away of data, your script becomes:

on ShaveMyFileName(MyFadeDate)

    set MyFadeName to my replace_chars(MyShowName, " ", "")
    display dialog MyFadeName

    set MyTrimTime to my replace_chars(MyFadeDate, " ", "")
    set MyTrimTime to my replace_chars(MyTrimTime, ",", "")
    set MyTrimTime to my replace_chars(MyTrimTime, ":", "")
    display dialog MyTrimTime

end ShaveMyFileName

This will have what I believe is the intended function: spaces will be
removed from MyShowName (with the result in MyFadeName), and spaces,
commas, and colons will be removed from MyFadeDate (with the result in
MyTrimTime).

I do not know where you are getting MyShowName (as you're not passing
it in), and you're never returning either of the results from this
function, so it's unclear how you'd use them in some other part of the
program... but hopefully this is a little closer to what you want.

-- 
Jerry Kindall, Seattle, WA                <http://www.jerrykindall.com/>

        Send only plain text messages under 32K to the Reply-To address.
        This mailbox is filtered aggressively to thwart spam and viruses.
 




 3 Posts in Topic:
headache.
Joshua Whalen <joshuaf  2008-02-17 15:18:19 
Re: headache.
Jerry Kindall <jerryki  2008-02-17 12:49:17 
Re: headache.
jb@[EMAIL PROTECTED] (Jo  2008-02-18 21:10:03 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 0:10:52 CDT 2008.