Solved

How to add prefix to a string?

Posted on 2014-10-09
3
407 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
  • 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now