Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

why isn't there a string concatenation operator?

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
developingprogrammer
Asked:
developingprogrammer
  • 3
  • 2
2 Solutions
 
frankhelkCommented:
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
 
developingprogrammerAuthor Commented:
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
 
Subrat (C++ windows/Linux)Software EngineerCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
developingprogrammerAuthor Commented:
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
 
Subrat (C++ windows/Linux)Software EngineerCommented:
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
 
developingprogrammerAuthor Commented:
thanks subrat and frank! i've definitely got my answer for this question! = )
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now