Skip to main content
1 of 2
rhermans
  • 37.4k
  • 4
  • 61
  • 152

A larger string list

l = With[
   {size = 100},
   MapAt[
    StringJoin[" ", #, " "] &,
    RandomChoice[CharacterRange["a", "z"], {size, size}],
    RandomInteger[{1, size}, {size, 2}]
    ]];

My own @rhermans

First@RepeatedTiming[ 
  StringDelete[" "] /@ l
  ]
(* 0.000750 *)

@murray

First@RepeatedTiming[ 
  StringTrim /@ l
  ]
(* 0.00497 *)

@Coolwater

First@RepeatedTiming[
  StringReplace[#, " " -> ""] & /@ l
  ]
(* 0.000801 *)

@Coolwater operator mode

First@RepeatedTiming[
  StringReplace[" " -> ""] /@ l
  ]
(* 0.000757 *)

@Kuba

First@RepeatedTiming[
  Map[StringTrim, l, {-1}]
  ]
(* 0.0482 *)
rhermans
  • 37.4k
  • 4
  • 61
  • 152