Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

why isn't there a string concatenation operator?

Posted on 2014-02-28
6
Medium Priority
?
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
frankhelk earned 1000 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 9

Assisted Solution

by:Subrat (C++ windows/Linux)
Subrat (C++ windows/Linux) earned 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 9

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

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.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

715 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