How do i use the Regex once again to filter for words that are letters only ? (not chars like...

  • Thread starter Thread starter Chocolade1972
  • Start date Start date
C

Chocolade1972

Guest
This is my code in a button click event:


StringBuilder sb = new StringBuilder();
var words = Regex.Split(textBox1.Text, @"(?=(?<=[^\s])\s+)");
var matches = Regex.Matches(textBox1.Text, "\\w+").Cast<Match>().Select(match => match.Value);
foreach (string word in words)
{
ScrambleTextBoxText scrmbltb = new ScrambleTextBoxText(word.Trim());
scrmbltb.GetText();
sb.Append(word.Replace(word.Trim(), scrmbltb.scrambledWord));
}
textBox2.AppendText(sb.ToString());


The variable words make that i will get the words from textBox1 including the spaces between each word then i make some stuff with the words and copy/add it to textBox2.


Its working if i type manualy in textBox1 some words like: hi danny hello bye hey

But if i load a text file into the textBox1 in this case the text file contain chars like: \r\n and ------ and others which are not letters

And when the code try to use this chars as words im getting an error/exception.


So i added this line:


var matches = Regex.Matches(textBox1.Text, "\\w+").Cast<Match>().Select(match => match.Value);


To get only words which are built from letters.

The problem is how do i use the variable matches with my code now ? Since im using the variable words already.

I want to use both filters one for words with the spaces and one for the letters only.

Continue reading...
 
Back
Top