Solved

why isn't there a string concatenation operator?

Posted on 2014-02-28
6
306 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now