Quantcast
Viewing latest article 4
Browse Latest Browse All 5

Answer by Bob Hanlon for How can I transform the string to a list?

Post actual data and code rather than images.

Clear["Global`*"];b1 = {a, b, c, d, e};b2 = {1, 2, 3, 4, 5};b3 = Thread[b1 -> b2];b4 = StringReplace[ToString /@ b3, "->" -> "-"](* {"a - 1", "b - 2", "c - 3", "d - 4", "e - 5"} *)

Alternatively, without ever generating b3

b5 = ToString[#[[1]]] <> " - " <> ToString[#[[2]]] & /@ Transpose[{b1, b2}](* {"a - 1", "b - 2", "c - 3", "d - 4", "e - 5"} *)

The approaches produce identical results.

b4 === b5(* True *)

Viewing latest article 4
Browse Latest Browse All 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>