Home > DeveloperSection > Forums > How to Edit richtextbox to retain only words that contains underscore
Andrew Deniel
Andrew Deniel

Total Post:29

Points:203
Posted on    September-28-2013 8:01 AM

 C# C# 
Ratings:


 1 Reply(s)
 704  View(s)
Rate this:
I need some help to define how I can edit the text in the richtextbox. For example, I will paste the following text on the rtextbox:

*"Release to user USER the roles: VDSF_DFGSD_DFGD_DFG_DFG_1, DFGDFG_DFGDG_DFGDFG_DFGDG_2, DFGDFG_DFGDF_DFGD_DFGDF_SADFSDF_3, SDF_SDFSD_DFGH_HJFHJ_FGDFGD_4, DFGDFU_DFGDDFGD_DFGDF_5, Q_FGDFG_6, FF_DFGDF_7"*

Then I want to edit this to keep only the text that contains the underscore("_"), and separate them in a new line, like this:

VDSF_DFGSD_DFGD_DFG_DFG_1

DFGDFG_DFGDG_DFGDFG_DFGDG_2

DFGDFG_DFGDF_DFGD_DFGDF_SADFSDF_3

SDF_SDFSD_DFGH_HJFHJ_FGDFGD_4

SDF_SDFSD_DFGH_HJFHJ_FGDFGD_5

DFGDFU_DFGDDFGD_DFGDF_6

Q_FGDFG, FF_DFGDF_7



Ida B Wells
Ida B Wells

Total Post:30

Points:210
Posted on    September-28-2013 8:57 AM

var text = @"Release to user USER the roles: VDSF_DFGSD_DFGD_DFG_DFG_1, DFGDFG_DFGDG_DFGDFG_DFGDG_2, DFGDFG_DFGDF_DFGD_DFGDF_SADFSDF_3, SDF_SDFSD_DFGH_HJFHJ_FGDFGD_4, DFGDFU_DFGDDFGD_DFGDF_5, Q_FGDFG_6, FF_DFGDF_7"

var words = text.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

var wordsWithUnderscores = words.Where(o => o.Contains("_")).ToArray();
 
foreach(var word in wordsWithUnderscores) {
    Console.WriteLine(word);
}

Don't want to miss updates? Please click the below button!

Follow MindStick