Reverse the gender of a string: Difference between revisions

added MiniScript example
(added MiniScript example)
Line 200:
His dog belongs to her but her dog is his!
</pre>
 
=={{header|MiniScript}}==
<lang MiniScript>cap = function(w) // (capitalize a word)
return w[0].upper + w[1:]
end function
 
trans = {"she":"he", "her":"his", "hers":"his"}
trans = trans + {"he":"she", "his":"her", "him":"her"}
 
for k in trans.indexes
trans[cap(k)] = cap(trans[k])
end for
 
reverseGender = function(s)
s = s.replace(".", " .").replace(",", " ,").replace("?", " ?").replace("!", " !")
words = s.split
for i in words.indexes
if trans.hasIndex(words[i]) then words[i] = trans[words[i]]
end for
s = words.join
s = s.replace(" .", ".").replace(" ,", ",").replace(" ?", "?").replace(" !", "!")
return s
end function
 
test = function(s)
print "BEFORE: " + s
print "AFTER: " + reverseGender(s)
print
end function
 
test "She was a soul stripper. She took his heart!"
test "He was a soul stripper. He took her heart!"
test "She wants what's hers, he wants her and she wants him!"
test "Her dog belongs to him but his dog is hers!"</lang>
 
{{out}}
<pre>BEFORE: She was a soul stripper. She took his heart!
AFTER: He was a soul stripper. He took her heart!
 
BEFORE: He was a soul stripper. He took her heart!
AFTER: She was a soul stripper. She took his heart!
 
BEFORE: She wants what's hers, he wants her and she wants him!
AFTER: He wants what's his, she wants his and he wants her!
 
BEFORE: Her dog belongs to him but his dog is hers!
AFTER: His dog belongs to her but her dog is his!</pre>
 
=={{header|Objeck}}==
222

edits