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
Solved

C# add text after hyphon (-) in a textbox

Posted on 2013-01-09
3
363 Views
Last Modified: 2013-01-09
How can I add text after hyphon in textbox:

kjhkjhkjh - add text here??
0
Comment
Question by:pauledwardian
3 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38761317
How about:

string result = original.Replace("-", "- " + addedText);

Open in new window

0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 38761358
Try something like:

        private void button2_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.IndexOf("-") > -1)
            {
                this.textBox1.Text = this.textBox1.Text.Substring(0, this.textBox1.Text.IndexOf("-") + 1) + "my added text";
            }
        }

Open in new window


If you need to preserve initial text after "-" (if existed), you may add another substring:


this.textBox1.Text.Substring(this.textBox1.Text.IndexOf("-")+1,
this.textBox1.Text.Length - this.textBox1.Text.IndexOf("-") -1);
0
 

Author Closing Comment

by:pauledwardian
ID: 38761384
Perfect!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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