Jump to content

I have a question about string variables.

- - - - -

  • Please log in to reply
8 replies to this topic

#1
nmoghan

nmoghan

    Newbie

  • Members
  • Pip
  • 8 posts
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. :)

#2
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 242 posts
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
nmoghan

nmoghan

    Newbie

  • Members
  • Pip
  • 8 posts
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.

#4
nmoghan

nmoghan

    Newbie

  • Members
  • Pip
  • 8 posts
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.

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
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.

#6
nmoghan

nmoghan

    Newbie

  • Members
  • Pip
  • 8 posts
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
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
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.

#8
nmoghan

nmoghan

    Newbie

  • Members
  • Pip
  • 8 posts
Ok i see thank you for your help really appreciated. :)

#9
nakor

nakor

    Newbie

  • Members
  • Pip
  • 3 posts

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.

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