Solved

why isn't there a string concatenation operator?

Posted on 2014-02-28
6
310 Views
Last Modified: 2014-03-02
hi guys, this is my first question on objective c on EE = )

Question 1: from a "philosophical" point of view, why can't i just do the below?

NSString * test = @"this is " + @"a sentence"

Open in new window


why does this work in VB but not objective c? i'm trying to understand the underlying difference between the 2 framework paradigms.

Question 2: under Topics, there is no objective c. there is only c, c#, c++. what should i search for in EE if i want to ask iOS questions? thanks!
0
Comment
Question by:developingprogrammer
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
frankhelk earned 250 total points
ID: 39894737
I havn't used "Objectice C" ever, but have done a fast "what's it" search.

As far as I can see, it is very close to regular C ... mostly a "Standard C with some extras". Therefore I could speculate on Q2 by "The questions could mostly be sorted into [C]".

To your initial question: The classic C doesn't know "strings" as intrinsic type like VB (or the C++ runtime) does. Strings in C are merely a pointer to a NULL terminated array of characters and could be accessed exactly that way. There's not even a length stored anywhere ... the routines have to count the characters when you need the length. Since C is not object oriented, there are no methods attatched to string variables and no operator overload is possible.

Due to that design - which by the way opens numerous elegant ways of string manipulation while keeping the overhead of strings neglectible - you have to rely on the stdlib routines to manipulate strings (or roll your own if they do't fit your needs). And these routines provide almost anything you need for regular string operations.

If you're addicted to all the OO mumbo-jumbo, you'll have to switch to C++. If you need fast and lean code (i.e. for drivers and kernel), you'll better stay with C.
0
 

Author Comment

by:developingprogrammer
ID: 39894748
hi frank, thanks for your speedy response!

classic C doesn't know "strings" as intrinsic type like VB

i think this hits the nail on the head = )

for question 2 - i'm starting to pick up iOS programming and was wondering what topic to put it under = )
0
 
LVL 8

Assisted Solution

by:Subrat (C++ windows/Linux)
Subrat (C++ windows/Linux) earned 250 total points
ID: 39896508
while you are saying "xnghsgdsgd" + "jjsdjsdskd", it's nothing but you are doing addition of two addresses which is not meaningful.

In C, string is a chat* which is nothing but address.While saying add two string, you are saying add two addresses.
But if you use C++, there is std::string class where + operator is overloaded. So + operator knows how to do concatenation. As said before.

You should use strcat() or wcscat()(for unicode) to perform the concatenation of strings in C.
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:developingprogrammer
ID: 39896603
thanks subrat! hey i'm sorry if i'm asking a repeated question here again, but how do i get advise specifically on objective c?

You should use strcat() or wcscat()(for unicode) to perform the concatenation of strings in C.

this is great but i am learning how to build my own iOS app so how should i search in EE for it? thanks subrat for your help! = )
0
 
LVL 8

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 39897959
It' simple. you have to select Obective C as the tag/topic while asking a question.I hope you are in right path.This Q. might not be seen by any Obective C experts:)
0
 

Author Closing Comment

by:developingprogrammer
ID: 39898500
thanks subrat and frank! i've definitely got my answer for this question! = )
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question