RosettaCodeData/Task/Determine-if-a-string-is-squeezable/Mathematica/determine-if-a-string-is-squeezable.math
2023-07-01 13:44:08 -04:00

16 lines
541 B
Text

ClearAll[Squeeze]
Squeeze[s_String,sq_String]:=StringReplace[s,x:(sq..):>sq]
s={
"",
"\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln",
"..1111111111111111111111111111111111111111111111111111111111111117777888",
"I never give 'em hell, I just tell the truth, and they think it's hell. ",
" --- Harry S Truman "
};
Squeeze[s[[1]],""]
Squeeze[s[[2]],"-"]
Squeeze[s[[3]],"7"]
Squeeze[s[[4]],"."]
Squeeze[s[[5]]," "]
Squeeze[s[[5]],"-"]
Squeeze[s[[5]],"r"]