3
$\begingroup$

I am finding difficulties to create several lines of text using the following described below:

enter image description here

I tried to use the functions: ToStrings, TextString, ToExpression, but nothing worked out.

The difficulty arises because the existence of "spaces", "<", ">","/" that need to be used in this texts.

I intend to enter values from a list at each step. Including the zeros must remain. "1" must be "01":

values={{01,03,05},{08,09,10},{07,08,15}}

This is one of my attempts, but without sucess:

ToString["  <valores="#" dataCriacao=\"24/11/2016\" grupo=\"Grupo1\">
   <conc=\"-1\" dataAssociacao=\"01/12/2016\" />
 </LMC>"] & /@ values

How should I proceed?

Update

The values of the list should be separated by spaces.

This is the result I want to get:

enter image description here

$\endgroup$
0

2 Answers 2

3
$\begingroup$
template = "  <valores=\"``\" dataCriacao=\"24/11/2016\" \
grupo=\"Grupo1\">
    <conc=\"-1\" dataAssociacao=\"01/12/2016\" />
  </LMC>";

Apply[StringJoin][
 StringTemplate[
    template, InsertionFunction -> StringRiffle   (*ads " " between*)
 ] /@ IntegerString[values, 10, 2]                (*makes "01" from 1*)
]
$\endgroup$
3
$\begingroup$

You will need to use StringJoin, ToString and Riffle to get everything in the right place. First, make the values into strings:

values = {
  {01, 03, 05}, {08, 09, 10}, {07, 08, 15}
} /. {
  (*Replace all single digit integers with 0 followed by the number as a string*)
  x_Integer /; x < 10 :> "0" <> ToString[x], 
  (*Replace all double digit integers with the number as a string*)
  x_Integer /; x > 9 :> ToString[x]
};

Next, use Riffle and StringJoin to make each of the sets of three into a single string:

strings = StringJoin[Riffle[#, " "]] & /@ values;

Finally, put these into your full string:

StringJoin[{
  "  <valores= \"", 
  ToString[#], 
  "\"  dataCriacao=\"24/11/2016\" grupo=\"Grupo1\">
   <conc=\"-1\" dataAssociacao=\"01/12/2016\" />
 </LMC>"
}] & /@ strings

(*{"  <valores= \"01 03 05\"  dataCriacao=\"24/11/2016\" grupo=\"Grupo1\
\">
    <conc=\"-1\" dataAssociacao=\"01/12/2016\" />
  </LMC>", "  <valores= \"08 09 10\"  dataCriacao=\"24/11/2016\" \
grupo=\"Grupo1\">
    <conc=\"-1\" dataAssociacao=\"01/12/2016\" />
  </LMC>", "  <valores= \"07 08 15\"  dataCriacao=\"24/11/2016\" \
grupo=\"Grupo1\">
    <conc=\"-1\" dataAssociacao=\"01/12/2016\" />
  </LMC>"}*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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