Skip to main content
2 of 2
deleted 5 characters in body
rhermans
  • 37.4k
  • 4
  • 61
  • 152

With a larger string list

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

My own

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