Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. conv01 = Map["["<>StringJoin@@Riffle[#,","]<>"]"&,Map[ToString,#,{2}],{0,1}]&
  2.  
  3. list = {{1, 2, "test3"}, {3, 4, "test4"}}
  4.  
  5. "[[1, 2, "test3"], [3, 4, "test4"]]"
  6.  
  7. conv03 = Map["[" <> ToString@Row[#, ","] <> "]" &, list, {0, 1}]
  8.  
  9. "[" <> ToString@Row[{1, 2, 3, 4}, ","] <> "]"
  10.  
  11. ExportString[{
  12. {1, 2, "Three"},
  13. {4, 5, "{Six}"}
  14. }, "JSON"]
  15.  
  16. list = {{1, 2, "test3"}, {3, 4, "test4"}};
  17. StringReplace[ToString@FullForm@list, "List[" -> "["]
  18.  
  19. "[[1, 2, "test3"], [3, 4, "test4"]]"
  20.  
  21. bracketFormat[expr_] :=
  22. StringReplace[
  23. ToString[expr, InputForm],
  24. {s : Shortest[""" ~~ __ ~~ """] :> s, "{" -> "[", "}" -> "]"}
  25. ]
  26.  
  27. list = {{1, 2, "test3"}, {3, 4, "test4", "trick{}"}};
  28.  
  29. bracketFormat[list]
  30.  
  31. "[[1, 2, "test3"], [3, 4, "test4", "trick{}"]]"
  32.  
  33. [[1, 2, "test3"], [3, 4, "test4", "trick{}"]]
  34.  
  35. With[{s = StringJoin@RandomChoice[CharacterRange["a", "z"], 30]},
  36. StringReplace[ToString[list /. {x_String :> """ ~~ x ~~ """, List -> s}], s -> ""]
  37. ]
  38. (* [[1, 2, "test3"], [3, 4, "test4"]] *)
  39.  
  40. list={{1,2,"123"},{1,2,"123"}};
  41.  
  42. Module[{$replace$},
  43. StringReplace[ToString@FullForm@Map[ $replace$@@#&,list,{0,1}],ToString@$replace$->""]
  44. ]
  45.  
  46. ToExpression@"{{2,3,"List[thiswouldbreaksomeothermethods] test{123}"},{3,5,"more [stuff]"}}" /. List :> ("[" <> StringJoin[ToString /@ {##}~Riffle~","] <> "]" &)
  47.  
  48. {{2,3,"List[thiswouldbreaksomeothermethods] test{123}"},{3,5,"more [stuff]"}} /. List :> ("[" <> StringJoin[ToString /@ {##}~Riffle~","] <> "]" &)
  49.  
  50. "[[2,3,List[thiswouldbreaksomeothermethods] test{123}],[3,5,more [stuff]]]"
  51.  
  52. ListFormat -> {"[", ",", "]"}
  53.  
  54. quoted /: TextString[quoted[str_]] := """ <> str <> """;
  55.  
  56. quoted /: TextString[quoted[str_String]] := """ <> str <> """;
  57. quoted /: TextString[quoted[str_]] := TextString@str;
  58.  
  59. TextString[MapAll[quoted, list], ListFormat -> {"[", ",", "]"}]
  60. (* "[[1,2,"test3"],[3,4,"test4"]]" *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement