Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

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

kjhkjhkjh - add text here??
0
Comment
Question by:pauledwardian
[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
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 30

Accepted Solution

by:
anarki_jimbel earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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