Solved

How to add prefix to a string?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

733 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