Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Hello stackexchange community!

I have a stringlist with a value and his error for eg:

{{"12","1"},{"13","2"}}

Now i want to output this as something like this (for a lab-report):

{"12(1)","13(2)"}

Unfortunately I have no idea how to get this working...

Thanks in advance
Cx

share|improve this question
    
Your first list as pasted does not contain strings, but integers. Could you clarify? –  Yves Klett Nov 11 '13 at 13:09
    
sorry, i corrected the error now –  cxkoda Nov 11 '13 at 13:21
    
now I solved it like this: errformat[list_] := Table[StringJoin[ToString[list[[i, 1]]], "(", ToString[list[[i, 2]]], ")"], {i, 1, Dimensions[list][[1]]}] –  cxkoda Nov 11 '13 at 13:32
    
thanks for your tipps –  cxkoda Nov 11 '13 at 13:33
    
I would recommend Chris` solution, which is clean&instructive. BTW, try Length[list]. –  Yves Klett Nov 11 '13 at 13:35

4 Answers 4

Using Apply:

StringJoin[#1, "(", #2, ")"] & @@@ {{"12", "1"}, {"13", "2"}}

{"12(1)", "13(2)"}

share|improve this answer
    
Cleaner than mine :-) –  Yves Klett Nov 11 '13 at 13:34

Depending on what you intend to do with the output you may also use StringForm:

StringForm["``(``)", ##] & @@@ {{"12", "1"}, {"13", "2"}}

{12(1),13(2)}

Internally this remains as a StringForm expression which may be good or bad given the circumstance.

share|improve this answer

Or with a pattern:

{{"12", "1"}, {"13", "2"}} /. {a_String, b_String} :> StringJoin[a, "(", b, ")"]
share|improve this answer

Depending on your exact input/output you could start with this and modifiy it according to your wishes:

ToString[#[[1]]] <> "(" <> ToString[#[[2]]] <> ")" & /@ {{12,1}, {13, 2}}

{"12(1)", "13(2)"}

Edit: with all elements as strings, you can dump ToString:

#[[1]] <> "(" <> #[[2]] <> ")" & /@ {{"12", "1"}, {"13", "2"}}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.