Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.9K Views
|
9 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Delete lines in a Wordlist.txt that contain specified chars

Posted 6 years ago

Hello community, I started to learn Wolfram Mathematica v12.0 some days ago and now I want to solve a little Problem.

There is a Wordlist.txt with German, Chinese and some other signs/symbols in it. Now I want to remove every line/word in it, that contains something different then “abc..., ABC....,123...., and !?”.

I did many exercises and one of them was about strings, but I don’t understand how to put those things together yet.

Thanks for some help, with best regards :3

p.s. sorry about my English, missed practicing a very long time :0

POSTED BY: Chris Bart
9 Replies
Posted 6 years ago

Hello Rohit,

Yes this is exactly what I was thinking of and it works great. Thank you for your time and effort.

Have a nice day.

Greetings,

Christian

POSTED BY: Chris Bart
Posted 6 years ago

Hi Christian,

I created a sample file wordlist.txt (see attached).

includeChars = {CharacterRange["A", "Z"], CharacterRange["a", "z"], 
    CharacterRange["0", "9"], "!", "?", " "} // Flatten;

wordList = Import["~/wordlist.txt", "Data"]

filtered = wordList // Select[StringFreeQ[#, Except[includeChars]] &]

Export["~/filteredList.txt", filtered]

The file filteredList.txt has the lines that only have the characters in includeChars.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard
Be respectful. Review our Community Guidelines to understand your role and responsibilities. Community Terms of Use