2010-07-02 7 views
1

Je suis en train de faire quelque chose comme ceci:citations c et les variables

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:@"tell application \"terminal\" to do script " charlieImputSelf " in front window"]; 
[sendCharlieImput executeAndReturnError:nil]; 

La charlieImputSelf variables va être mis dans la fenêtre de terminal comme une commande. MAIS j'ai besoin de mettre charlieImputSelf entre 2 qoutes (comme ci-dessus). Ce n'est évidemment pas la bonne façon. Quelqu'un peut-il aider?

Merci! Elijah

Répondre

3

Utilisez la méthode de +stringWithFormat:NSString:

NSAppleScript *sendCharlieImput = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"tell application \"Terminal\" to do script %@ in front window", charlieImputSelf]]; 
10

Pour réussir, vous aurez besoin d'embrasser la documentation. Start here. Ensuite, allez read this.

Le fait de devoir poser une question sur SO à propos de chaque ligne de code n'aboutira pas au succès.

Pour répondre à cette question, vous voulez stringWithFormat::

[NSString stringWithFormat: @"some random string \"with quotes\" and %@ word in the middle.", @"this"];