Pages: [1]   Go Down
Author Topic: Passing String objects as parameters to a function  (Read 1290 times)
0 Members and 1 Guest are viewing this topic.
NS Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello All,
         I am a newbie to C. All I know about it has come from working with Arduino. This is my current hang-up, on which I have worked for hours.
I want to be able to pass alphanumeric strings in the form of String objects to a function which does some formatting on it and passes it back in the formatted state. I want to be able to call this function from various points in the sketch with Stings of various names.  I'm sure this can be done but I can't figure out the syntax.  Basically it would look like this....

Code:
String MyString = "some alphanumeric text";

void loop(){
    format_string(MyString);
}

void format_string (String anyString){
   //do some formatting
}

I'd appreciate any help.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13072
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
void format_string (String & anyString){
   //do some formatting
}
« Last Edit: March 31, 2011, 01:58:04 pm by Coding Badly » Logged

NS Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a bunch. That works.
Your reply has got to be the all-time briefest successful reply to a query... one character long! No one can beat that. It is an atom of language.
Gives new meaning to,  "Let me give you a "bit" of advice. smiley-grin
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13072
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley-lol
Logged

Pages: [1]   Go Up
Jump to: