473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to seperate values in a string?

TheMan1
19
NEWB QUESTION.
I don't mean split. I mean just have multiple values making up a string.

ie. string tmp = "blah" + variable1 + variable2 + "blahblah";

This obviously doesn't work. How can I make all of this into one string?
Mar 13 '08 #1
7 1662
sicarie
4,677 Expert Mod 4TB
NEWB QUESTION.
I don't mean split. I mean just have multiple values making up a string.

ie. string tmp = "blah" + variable1 + variable2 + "blahblah";

This obviously doesn't work. How can I make all of this into one string?
So while that is pretty close to java code, you don't say what language you will be working in. Is this C or C++?

Did you look at strcat()?
Mar 13 '08 #2
TheMan1
19
I'm working in C++.
And I don't think strcat() is what I'm looking for. I just want to combine different things into one string.
Mar 13 '08 #3
sicarie
4,677 Expert Mod 4TB
What do you mean by different things?

Different variable types?
Mar 13 '08 #4
oler1s
671 Expert 512MB
And I don't think strcat() is what I'm looking for.
I fail to understand. You do want to create a larger string by joining up smaller strings, which is precisely what concatenation is. Perhaps the confusion lies over:

I just want to combine different things into one string.
To summarize, you have different variables, of different types, that you want to be combined into a string type. In the end, it's still concatenation, as all variables that aren't strings have to be turned into strings, then all those strings have to be concatenated.

My first thought when I saw your question was stringstream. Can you look up C++ stringstreams, and tell us if they are along the lines of what you are looking for?
Mar 13 '08 #5
Sick0Fant
121 100+
Literals are of type char *. You'll have to typecast your literals as strings (or overload the + operator).
Mar 13 '08 #6
weaknessforcats
9,208 Expert Mod 8TB
Do not use strcat or any of the C string library functions. They are all deprecated in C++.

Your example does work if it's coded correctly:
Expand|Select|Wrap|Line Numbers
  1. char variable1[] = "A";
  2.  char variable2[] = "B";
  3. string tmp =  "blah" + string(variable1) + string(variable2) + "blahblah";
  4.  
You can't just have variable1 + variable2 since these are pointers and you can't add two pointers. Instead, you create temprary string objects for the operator+.
Mar 13 '08 #7
TheMan1
19
Do not use strcat or any of the C string library functions. They are all deprecated in C++.

Your example does work if it's coded correctly:
Expand|Select|Wrap|Line Numbers
  1. char variable1[] = "A";
  2.  char variable2[] = "B";
  3. string tmp =  "blah" + string(variable1) + string(variable2) + "blahblah";
  4.  
You can't just have variable1 + variable2 since these are pointers and you can't add two pointers. Instead, you create temprary string objects for the operator+.
Thanks, that's just what I was looking for.
Mar 22 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: jason | last post by:
How do I seperate the "chk_" and "33" in the following string: chk_33 Thanks Jason
2
by: David | last post by:
Hi all, I am fairly new to C#. so go easy on me :-) Anyhow, I have a class file that I have set up properties and a method. I am calling this class file directly from and aspx.cs file. So...
4
by: JeffM | last post by:
Quick C# question: I have comma delimited values in a string array that I want to pass to seperate variables. Any tips on splitting the array? Thanks in advance! JM
7
by: Jon S via DotNetMonster.com | last post by:
Hi all, I posted this yesterday but didnt explain it too well so thought I would do it again. I have a label on a form that I want to be able to change the text while I'm in a seperate class...
6
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create...
1
by: ScoobyNewbie | last post by:
Hi all Need help have created a standard rutin that open a file and write a line of what I think is tabb seperated string values according msdn help the Printline method should print the values...
6
by: Phil Latio | last post by:
I am missing a trick here on how use variables defined in seperate file. In script 1, I have proved to myself my class is working OK because I can pass in the values and the echo statement...
5
by: RAMBO29 | last post by:
Hi I am a bit new to this field and came across a small problem.I tried to find the solution for almost 2 days and havent been able to.I hope some one there can help.I am sure its a small things but...
34
by: bitsnbytes64 | last post by:
Hi, I've been having a similar issue to what is described in the "refresh a form" post with a ComboBox that is not being refreshed after adding a new value on a seperate form. The second form is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.