How to Edit richtextbox to retain only words that contains underscore

Total Post:29

Points:203
C# 
C#
 1274  View(s)
Ratings:
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

  1. Post:30

    Points:210
    Re: How to Edit richtextbox to retain only words that contains underscore

    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);
    }

      Modified On Mar-31-2018 03:57:29 AM

Answer