Hello people. I am a beginner in programming and i have a question about 'string' variables. If you help, i will be grateful.
string name = "mahmut";
string surname = "aslan";
string fullname = "... aslan";
//here is the question that i wanna ask. Is there a way that i can show the name 'mahmut' in fullname quotes without rewriting the word mahmut inside the fullname quotes ? :confused: If yes, could you please explain how ? It is some kinda homework for me. Thanks for the helps. :)
8 replies to this topic
#1
Posted 03 September 2010 - 11:46 AM
|
|
|
#2
Posted 03 September 2010 - 12:47 PM
I'm not sure what you are asking. Are you trying to build a string called fullname out of the other parts of the name? Are you trying to convert the "..." to "mahmut"?
string fullname = name + " " + surname; // build a string called fullname
string fullname = "... alslan";
fullname = fullname.Replace("...", name); // changes all occurances of "..." to 'name'
#3
Posted 03 September 2010 - 12:51 PM
Oh, thank you very much my friend appreciated. I am just trying to write fullname without using the name again.
for ex:
fullname should be "mahmut aslan"
string name = "mahmut"
string fullname = "... aslan"
//how can i show the full name here without using the word "mahmut" in fullname quotes again.
for ex:
fullname should be "mahmut aslan"
string name = "mahmut"
string fullname = "... aslan"
//how can i show the full name here without using the word "mahmut" in fullname quotes again.
#4
Posted 03 September 2010 - 01:08 PM
i am not trying to convert "..." to "mahmut".
i need to show "mahmut" inside the fullname quotes without writing it inside the fullname quotes.
// i think it should be something like this
string name = "mahmut";
string fullname = name + "aslan";
//but i couldn't manage to make the name "mahmut" occur in fullname string without writing it.
i need to show "mahmut" inside the fullname quotes without writing it inside the fullname quotes.
// i think it should be something like this
string name = "mahmut";
string fullname = name + "aslan";
//but i couldn't manage to make the name "mahmut" occur in fullname string without writing it.
#5
Posted 03 September 2010 - 02:51 PM
He just showed you a method using "fullname.Replace("...", name);"
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#6
Posted 03 September 2010 - 02:58 PM
I have already done that thank you mate. But i was asking if there had been a way to show "mahmut" on string fullname instead of "name". However i started to beleive that it is impossible :D
#7
Posted 03 September 2010 - 03:02 PM
name is "mahmut", so you're replacing the "..." with "mahmut", that is the only way you can do so without using mahmut in double quotes.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#8
Posted 03 September 2010 - 03:03 PM
Ok i see thank you for your help really appreciated. :)
#9
Posted 11 September 2010 - 12:16 PM
nmoghan said:
i am not trying to convert "..." to "mahmut".
i need to show "mahmut" inside the fullname quotes without writing it inside the fullname quotes.
// i think it should be something like this
string name = "mahmut";
string fullname = name + "aslan";
//but i couldn't manage to make the name "mahmut" occur in fullname string without writing it.
i need to show "mahmut" inside the fullname quotes without writing it inside the fullname quotes.
// i think it should be something like this
string name = "mahmut";
string fullname = name + "aslan";
//but i couldn't manage to make the name "mahmut" occur in fullname string without writing it.
you're just wanting to append aslan to the end of mahmut from what I can gather. No need for using Replace, should just be something along the lines of
string name = "mahmut"; string surname = "aslan"; string fullname = name + " " + surname;
but if you are wanting to replace some text with mahmut then yes, you'll need to use Replace
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









