Message Boards Message Boards

0
|
8575 Views
|
8 Replies
|
7 Total Likes
View groups...
Share
Share this post:

[?] Delete empty spaces in a list?

Hi,

Which command can use for deleting empty space for the below list?

S1 = {"5", "10", "7", "", "", "", "", ""}

Thank for your help.

POSTED BY: M.A. Ghorbani
8 Replies

A more general approach if you only want to select the stings that actually are a number.

Select[S1, StringMatchQ[#, NumberString] &]
POSTED BY: Martijn Froeling

I know it's not the same thing as deleting, but with the Drop command also arrives at the same result.

S1 = {"5", "10", "7", "", "", "", "", ""};
Drop[S1, {-5, -1}]
(* {5,10,7} *)
POSTED BY: Claudio Chaib

Sander is correct. You typed what he posted incorrectly. You want to delete the empty strings so you must enter “”, not “,,”

Regards

POSTED BY: Neil Singer

Why not simply:

DeleteCases[S1,""]

?

POSTED BY: Sander Huisman

Hi Sander,

enter image description here

POSTED BY: M.A. Ghorbani

You right Sander. I appreciate your help.

POSTED BY: M.A. Ghorbani
DeleteCases[S1 /. "" -> x, x]
(* {"5", "10", "7"} *)
POSTED BY: Mariusz Iwaniuk

An interesting solution! Many thanks, Mariusz.

POSTED BY: M.A. Ghorbani
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract