Time and again we get into situations where we need to remove certain characters from a string. Like this StackOverflow question. Needless to say, rebol makes this easy and intuitive.
Why only punctuation?
For this discussion, punctuation is something like a tilde or a needless comma. We can also remove other things, like the word ji that us Indians and the word san that the Japanese like to use after people's names. Or some spelling mistake all across a string for that purpose. Read on.
replace/all
If there is only one word or character that we have to replace, we can use replace/all. We can replace either with an empty string or with some other word or character. Like:
Removing stuff
We will create a function that will take two inputs: a string! and a block!. The block will contain punctuation that we want to remove as strings. For each string in the block, we will apply replace/all on the string. See:
See forall if you are confused about lines 5 and 6. (You can have a look at forskip too.)
Usage:
If you want, you can replace with some other string. Or replace with a string, or a block of strings as arguments.
If there is anything you wish to say or ask, feel free to use the comments. Also, feel free to tell a better way of doing it. :-)
See forall if you are confused about lines 5 and 6. (You can have a look at forskip too.)
Usage:
If you want, you can replace with some other string. Or replace with a string, or a block of strings as arguments.
If there is anything you wish to say or ask, feel free to use the comments. Also, feel free to tell a better way of doing it. :-)
I had to study Computer programs in college for a sem. And how I hated doing that and religiously even flunked for the exam :D
ReplyDeleteP.S. Long time.... how come you not writing much these days?
I am definitely confused now.
ReplyDeleteHappy New Year KK.
I wonder why. ;)
DeleteOne of my sons has been a software analyst for over 20 years. We learned "Basic" together when I bought a Commodore Vic-20 in the 1980s. But he so excelled beyond my grasp of that and other computer languages that I happily withdrew from the competition. I now ask him for advice on the slightest programming matters. Sound familiar? Excellent post!
ReplyDelete