Solved

why isn't there a string concatenation operator?

Posted on 2014-02-28
6
302 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 13

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 opening and reading files in the C programming language.

757 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

23 Experts available now in Live!

Get 1:1 Help Now