Solved

How to add prefix to a string?

Posted on 2014-10-09
3
502 Views
Last Modified: 2014-10-09
How to add prefix to a string in c#?

For example I have a strin '1234' and I would like to add page as prefix to the string.

For example:  page1234

How can I implement this in c#?

Thanks.
0
Comment
Question by:developer2012
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
ID: 40370968
string mystring="1234";
mystring="page"+mystring;

Open in new window

0
 

Author Comment

by:developer2012
ID: 40370973
Is there anyway we can do it by Replace Method?
0
 
LVL 21

Assisted Solution

by:Randy Poole
Randy Poole earned 500 total points
ID: 40370990
You really are not replacing anything. But you could add a place holder to your string.  Or you could use insert:
Using place holder:
string mystring="*1234";
string repvalue="page";
mystring=mystring.replace("*",repvalue);

Open in new window

Insert method
string mystring="1234";
string repvalue="page";
mystring=mystring.Insert(0,repvalue);

Open in new window

0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

717 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