[HELP] Need a code

Junior Spellweaver
Joined
Dec 29, 2005
Messages
166
Reaction score
1
Does anyone know a code in command prompt that deletes a word in notepad if it is smaller and larger than 7 characters?

Thanks :)
 
You can't do this in the command prompt.

Best option is to use C, but PHP will do the job too. You generally need to write a code that will how many alpha (a-z) characters exist. When it finds a space or a period, it should reset the counter. And when the counter is 7 or higher, you can just replace the word by nothing.
 
PHP:
<?php
function removeWords($str){
$str = htmlspecialcharacters($str);
$arr = preg_split("/\s+/",$str);
foreach($arr as $key => $val){
  if(strlen($val) >= 7){
    unset($arr[$key]);
  }
}
return $arr;
}

/*
 Execution:
 
 $text = removeWords($removeWords);
 foreach($arr as $key => $val){
   echo $val." ";
 }
*/
?>
Okay I typed that up inside this window, untested and what not.
Might work might not lol
 
I would do it this way:

PHP:
<?php
function removeWords($str)
{
    return preg_replace('/[a-zA-Z]{7,}/', '', $str);
}

$text = 'Oohthiswordissoolong but this word isn\'t.';
echo removeWords($text);
?>

Neither sure if it works, just typed in this window either ^^,
 
That doesn't cover symbols, numbers etc. You would need to add more sets (ie 0-9) to it to get every word.

Yes, numbers and symbols do not appear in words, right? :P
 
Back