Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Maybe stupid question - Combining strings

Maybe stupid question - Combining strings
Thread Tools
Mac Elite
Join Date: Sep 2001
Location: The Land of Beer and Chocolates
Status: Offline
Reply With Quote
Dec 26, 2001, 01:36 PM
 
Maybe this is a very stupid question , but I am looking for a way to combine a string that doesn't change , and a varying string . I am making an update detection system for my app , and I would like it to say :
The newest version available is [and then the version number that is retrieved from the Internet .
I tried @"The newest version available is " + the dynamic string with the version number , but that didn't exactly work .
Can anybody help me ?
     
Mac Elite
Join Date: Dec 2001
Location: Paris, France
Status: Offline
Reply With Quote
Dec 26, 2001, 02:45 PM
 
can't you do
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
int ver_numb; <font color = brown>//Store your number here</font>
string text = <font color = red>"The newest version available is : "</font> + ver_numb
</font>[/code]
then display text?

That's what I'd do in Java
     
Mac Elite
Join Date: Sep 2001
Location: The Land of Beer and Chocolates
Status: Offline
Reply With Quote
Dec 26, 2001, 03:27 PM
 
Thanks , but it didn't work . I do have another question now , though
How can you read a file from the Internet with AppleScript ?
What I would like to do is read the contents of a text file (http://homepage.mac.com/janvanboghout/versie.txt for example) and display that in a text view . Is that possible ?
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Dec 26, 2001, 05:19 PM
 
Well, it's hard to know what will work unless we know what language you're using (*wink-wink*), but in AppleScript it would be:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>set ver_numb to [whatever the version is]
set text to <font color = red>"The newest version available is : "</font> & ver_numb</font>[/code]

and in PHP/Perl it would be:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>$ver_numb = [whatever the version is];
$text = <font color = red>"The newest version available is : "</font> . ver_numb;</font>[/code]

Note the period (.) in the PHP/Perl version...that's the string concatenation operator.[/LIST]
[ 12-26-2001: Message edited by: Wevah ]
[Wevah setPostCount:[Wevah postCount] + 1];
     
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Dec 26, 2001, 07:24 PM
 
Originally posted by Jan Van Boghout:
<STRONG>Thanks , but it didn't work . I do have another question now , though
How can you read a file from the Internet with AppleScript ?
What I would like to do is read the contents of a text file (http://homepage.mac.com/janvanboghout/versie.txt for example) and display that in a text view . Is that possible ?</STRONG>
I don't think it is possible with just AppleScript unless you download the file and then read it from the .. but that isn't practical.

You'd need to use a cocoa method...

in your project, create a new header file and call it whatever you want like "fileGetter.h" then put in this info:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>#import &lt;Foundation/Foundation.h&gt;


@interface fileGetter : NSObject {

}
+ (NSString *)getCode NSString *)path;
@end</font>[/code]

Then make a class file and call it whatever you want again like "fileGetter.m" and put in this:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>#import <font color = red>"fileGetter.h"</font>


@implementation fileGetter
+ (NSString *)getCode NSString *)path {
return [NSString stringWithContentsOfURL:[NSURL URLWithString ath]];
}
@end</font>[/code]

Then from your applescript, you can use this code...

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>on clicked theObject
tell window of theObject
set theCont to (call method <font color = red>"getCode:"</font> of class <font color = red>"fileGetter"</font> with parameter <font color = red>"http:<font color = brown>//homepage.mac.com/janvanboghout/versie.txt"</font>)</font>
set theCont to theCont as string
set contents of text field <font color = red>"mySourceField"</font> to theCont
end tell
end clicked</font>[/code]

Works for me. BTW, someone else did the cocoa for me, I don't know anything I am using it for my forum viewer.
     
Mac Elite
Join Date: Sep 2001
Location: The Land of Beer and Chocolates
Status: Offline
Reply With Quote
Dec 27, 2001, 05:04 AM
 
Thanks Synotic , I already found the Cocoa method on www.cocoadev.com , but I didn't know how to use the result in an AppleScript . This is exactly what I needed !
     
Fresh-Faced Recruit
Join Date: Jan 2001
Status: Offline
Reply With Quote
Dec 27, 2001, 02:46 PM
 
Originally posted by Jan Van Boghout:
<STRONG>Maybe this is a very stupid question , but I am looking for a way to combine a string that doesn't change , and a varying string .</STRONG>
In Obj-C, check out

file:///System/Library/Frameworks/Foundation.framework/Versions/C/Resources/English.lproj/Documentation/Reference/ObjC_classic/Classes/NSMutableString.html

- (void)appendString NSString *)aString

appendString is your friend. You could do

NSMutableString *foo = [NSString stringWithString:@"current version is"];
NSString *version;
version = //some function call to get current version
[[foo appendString:@" "] appendString:version];

(the first string is to add a space in between)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:10 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2