Solved

How to add prefix to a string?

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# bracket error 3 32
Delphi: barcode reading on android platform 1 30
Switching Visual Studio 2015 to normal debug display 3 28
Call Controller Action Method from ASPX 2 15
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

803 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