concatenation of multiple value [modified]
-
hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:
modified on Saturday, July 10, 2010 8:17 AM
-
hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:
modified on Saturday, July 10, 2010 8:17 AM
Console.WriteLine("helloworld");
:omg:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:
modified on Saturday, July 10, 2010 8:17 AM
Try:
string result = "welcome" + "to" + "hello" + "world";
string resultWithSpaces = string.Format("{0} {1} {2} {3}", "welcome", "to", "hello", "world");Each literal string "whatever" could be a variable string ion either case:
string strWelcome = "welcome";
string strTo = "to";
string strHello = "hello";
string strWorld = "world";
string result = strWelcome + strTo + strHello + strWorld;
string resultWithSpaces = string.Format("{0} {1} {2} {3}", strWelcome, strTo, strHello, strWorld);If you need them in a loop:
string[] text = {"welcome", "to", "hello", "world"};
string result = "";
string resultWithSpaces = "";
foreach (string s in text)
{
result += s;
resultWithSpaces += s + " ";
}The advanced stuff is to use a StringBuilder, but that can wait until you are certain of the basics!
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
-
hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:
modified on Saturday, July 10, 2010 8:17 AM
Three easy options, +, string.Format or StringBuilder The first two...
string newString = "welcome" + "to" + "hello" + "world";
string newString = string.Format("{0} {1} {2} {3}", "welcome", "to", "hello", "world");Dave
If this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
Try:
string result = "welcome" + "to" + "hello" + "world";
string resultWithSpaces = string.Format("{0} {1} {2} {3}", "welcome", "to", "hello", "world");Each literal string "whatever" could be a variable string ion either case:
string strWelcome = "welcome";
string strTo = "to";
string strHello = "hello";
string strWorld = "world";
string result = strWelcome + strTo + strHello + strWorld;
string resultWithSpaces = string.Format("{0} {1} {2} {3}", strWelcome, strTo, strHello, strWorld);If you need them in a loop:
string[] text = {"welcome", "to", "hello", "world"};
string result = "";
string resultWithSpaces = "";
foreach (string s in text)
{
result += s;
resultWithSpaces += s + " ";
}The advanced stuff is to use a StringBuilder, but that can wait until you are certain of the basics!
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
Sorry, didn't see your post! :doh:
Dave
If this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
Sorry, didn't see your post! :doh:
Dave
If this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)I do that as well... :laugh: (mostly, I tend to do it with the CCC - damnit!)
Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
-
hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:
modified on Saturday, July 10, 2010 8:17 AM
Look into System.Text.StringBuilder.
-
hii! please guide me regarding: i want concatenate "welcome", "to", "hello" and "world" together. like as: welcome to hello world these value are coming from via for loop. but if in case I don't know what the actually data store in database. what i do thanx thanx for every one:
modified on Saturday, July 10, 2010 8:17 AM
I do assume you know how to concatenate two strings and if you don't you should get a C# book and go through it. If you are not sure what order they words are coming from the database in, I'm afraid you cannot do a 'grammatically correct' concatenation unless you build your own language parser. That would mean writing tons of parsing logic and building your own language database.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.