Печать данных в Mathematica
У меня есть одна проблема с печатью данных в Mathematica. Если строка так долго, например
S=11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
Я хочу напечатать S в форме сначала пять пустых пробелов, затем поставить "#", затем 66 пробелов S, а затем ввести следующий порядок снова. Эта форма должна быть открыта в WordPad, как здесь
"5 spaces empty"#1111111111"(66times)"111111
"5 spaces empty"#1111111111"(66times)"111111
.....
С наилучшими пожеланиями,
1 ответ
Решение
Вы можете использовать следующий код:
In[58]:=
S=1111111111111111111111111111111111111111111111111111111111111111111111111111\
111111111111111111111111111111111111111111111111111111111111111111111111111111\
111111111111111111111111111111111111111111111111111111111111111111111111111111\
111111111111111111111111111111111111111111111111111111111111111111111111111111\
1111111111111111111111111111111111111111111111111111;
StringPartition[s_,l_]:=Table[StringTake[s,{i,Min[i+l-1,
StringLength[s]]}],{i,1,StringLength[s],l}];
fmts=Map[(" #"<>#<>"\r")&,StringPartition[ToString[S],66]];
(* Unfortunately the web software is ruining the formatting of the output, deleting the extra spaces I placed before the #, etc. *)
(* But if you fix all the things this web software broke when I pasted your result and then run this and check the output carefully you should see it is correct *)
FullForm[fmts]
Out[61]//FullForm=
List[
" #111111111111111111111111111111111111111111111111111111111111111111\r",
" #111111111111111111111111111111111111111111111111111111111111111111\r",
" #111111111111111111111111111111111111111111111111111111111111111111\r",
" #111111111111111111111111111111111111111111111111111111111111111111\r",
" #111111111111111111111111111111111111111111111111111111111111111111\r",
" #11111111111111111111111111111111\r"
]