RosettaCodeData/Task/Determine-if-a-string-is-squeezable/Mathematica/determine-if-a-string-is-squeezable.math

17 lines
541 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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"]