Jump to content

Reverse the gender of a string: Difference between revisions

m
J draft
m (→‎{{header|REXX}}: changed some whitespace.)
m (J draft)
Line 4:
<lang pseudocode>print rev_gender("She was a soul stripper. She took my heart!")
He was a soul stripper. He took my heart!</lang>
 
=={{header|J}}==
 
Note that we cannot do a good job for the general case of english text using simple rules. For example, consider:
 
* Give her the book.
* It is her book.
* Give him the book.
* It is his book.
 
For this simple example, to determine whether to change ''her'' to ''him'' or ''his'' we would need a grammatical representation of the surrounding context.
 
So, for now, we limit ourselves to the simple case specified in the task example, and do not even do all that great of a job there, either.:
 
<lang J>cheaptrick=: rplc&(;:'She He He She')</lang>
 
And, the task example:
 
<lang J> cheaptrick 'She was a soul stripper. She took my heart!'
He was a soul stripper. He took my heart!
cheaptrick cheaptrick 'She was a soul stripper. She took my heart!'
She was a soul stripper. She took my heart!</lang>
 
=={{header|Python}}==
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.