Is there a way to convert Wolfram Language expression to string? Planned maintenance scheduled...
Why is one lightbulb in a string illuminated?
Why does my GNOME settings mention "Moto C Plus"?
How is an IPA symbol that lacks a name (e.g. ɲ) called?
A German immigrant ancestor has a "Registration Affidavit of Alien Enemy" on file. What does that mean exactly?
What is the definining line between a helicopter and a drone a person can ride in?
Can this water damage be explained by lack of gutters and grading issues?
Does the Pact of the Blade warlock feature allow me to customize the properties of the pact weapon I create?
How to mute a string and play another at the same time
“Since the train was delayed for more than an hour, passengers were given a full refund.” – Why is there no article before “passengers”?
Does GDPR cover the collection of data by websites that crawl the web and resell user data
When does Bran Stark remember Jamie pushing him?
How do I overlay a PNG over two videos (one video overlays another) in one command using FFmpeg?
lm and glm function in R
Reflections in a Square
Can gravitational waves pass through a black hole?
Lights are flickering on and off after accidentally bumping into light switch
Do chord progressions usually move by fifths?
Why aren't these two solutions equivalent? Combinatorics problem
Why isn't everyone flabbergasted about Bran's "gift"?
Protagonist's race is hidden - should I reveal it?
What is the evidence that custom checks in Northern Ireland are going to result in violence?
Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?
Short story about an alien named Ushtu(?) coming from a future Earth, when ours was destroyed by a nuclear explosion
What's the difference between using dependency injection with a container and using a service locator?
Is there a way to convert Wolfram Language expression to string?
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?How can I get better formatting in ToString?Is there a way to hide or toggle the visibility of code?How to convert arbitrary raw boxes directly into String?Is there a way to use CellPrint on dataset objects?Is there a way to hide input cells, that have no output?Is there a way to obtain the time when an input was executed in a notebook?
$begingroup$
Is there a way to convert a Wolfram Language expression / code into a string expression? For example,
Convert the following including its indentations (very important),
If[Length[$ScriptCommandLine]==1,
Print["No expressions were given to square."],
args = Rest[$ScriptCommandLine];
squares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];
MapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]
]
into
"If[Length[$ScriptCommandLine]==1,
Print["No expressions were given to square."],
args = Rest[$ScriptCommandLine];
squares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];
MapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]
]".
I am looking for a builtin function or a function f that can be written to work like
f[...code...]→ ...string version of code....
I am trying to do this programmatically and probably will require going into the Cell expression.
cells
$endgroup$
add a comment |
$begingroup$
Is there a way to convert a Wolfram Language expression / code into a string expression? For example,
Convert the following including its indentations (very important),
If[Length[$ScriptCommandLine]==1,
Print["No expressions were given to square."],
args = Rest[$ScriptCommandLine];
squares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];
MapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]
]
into
"If[Length[$ScriptCommandLine]==1,
Print["No expressions were given to square."],
args = Rest[$ScriptCommandLine];
squares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];
MapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]
]".
I am looking for a builtin function or a function f that can be written to work like
f[...code...]→ ...string version of code....
I am trying to do this programmatically and probably will require going into the Cell expression.
cells
$endgroup$
$begingroup$
ToStringdoes this.
$endgroup$
– Roman
8 hours ago
$begingroup$
Something like this?StringReplace[ToString[Defer[2 + 2]], "Defer[" ~~ x___ ~~ "]" :> x]
$endgroup$
– user6014
8 hours ago
$begingroup$
Why exactly do you want to do this? What will you do with the string? Why is indentation important? The indentations are not part of the underlying Mathematica expression. You refer toCellexpression, but this only exists in the FrontEnd. What do you mean by that?
$endgroup$
– Somos
8 hours ago
add a comment |
$begingroup$
Is there a way to convert a Wolfram Language expression / code into a string expression? For example,
Convert the following including its indentations (very important),
If[Length[$ScriptCommandLine]==1,
Print["No expressions were given to square."],
args = Rest[$ScriptCommandLine];
squares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];
MapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]
]
into
"If[Length[$ScriptCommandLine]==1,
Print["No expressions were given to square."],
args = Rest[$ScriptCommandLine];
squares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];
MapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]
]".
I am looking for a builtin function or a function f that can be written to work like
f[...code...]→ ...string version of code....
I am trying to do this programmatically and probably will require going into the Cell expression.
cells
$endgroup$
Is there a way to convert a Wolfram Language expression / code into a string expression? For example,
Convert the following including its indentations (very important),
If[Length[$ScriptCommandLine]==1,
Print["No expressions were given to square."],
args = Rest[$ScriptCommandLine];
squares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];
MapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]
]
into
"If[Length[$ScriptCommandLine]==1,
Print["No expressions were given to square."],
args = Rest[$ScriptCommandLine];
squares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];
MapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]
]".
I am looking for a builtin function or a function f that can be written to work like
f[...code...]→ ...string version of code....
I am trying to do this programmatically and probably will require going into the Cell expression.
cells
cells
edited 7 hours ago
user64494
3,61411122
3,61411122
asked 8 hours ago
user13892user13892
1,327616
1,327616
$begingroup$
ToStringdoes this.
$endgroup$
– Roman
8 hours ago
$begingroup$
Something like this?StringReplace[ToString[Defer[2 + 2]], "Defer[" ~~ x___ ~~ "]" :> x]
$endgroup$
– user6014
8 hours ago
$begingroup$
Why exactly do you want to do this? What will you do with the string? Why is indentation important? The indentations are not part of the underlying Mathematica expression. You refer toCellexpression, but this only exists in the FrontEnd. What do you mean by that?
$endgroup$
– Somos
8 hours ago
add a comment |
$begingroup$
ToStringdoes this.
$endgroup$
– Roman
8 hours ago
$begingroup$
Something like this?StringReplace[ToString[Defer[2 + 2]], "Defer[" ~~ x___ ~~ "]" :> x]
$endgroup$
– user6014
8 hours ago
$begingroup$
Why exactly do you want to do this? What will you do with the string? Why is indentation important? The indentations are not part of the underlying Mathematica expression. You refer toCellexpression, but this only exists in the FrontEnd. What do you mean by that?
$endgroup$
– Somos
8 hours ago
$begingroup$
ToString does this.$endgroup$
– Roman
8 hours ago
$begingroup$
ToString does this.$endgroup$
– Roman
8 hours ago
$begingroup$
Something like this?
StringReplace[ToString[Defer[2 + 2]], "Defer[" ~~ x___ ~~ "]" :> x]$endgroup$
– user6014
8 hours ago
$begingroup$
Something like this?
StringReplace[ToString[Defer[2 + 2]], "Defer[" ~~ x___ ~~ "]" :> x]$endgroup$
– user6014
8 hours ago
$begingroup$
Why exactly do you want to do this? What will you do with the string? Why is indentation important? The indentations are not part of the underlying Mathematica expression. You refer to
Cell expression, but this only exists in the FrontEnd. What do you mean by that?$endgroup$
– Somos
8 hours ago
$begingroup$
Why exactly do you want to do this? What will you do with the string? Why is indentation important? The indentations are not part of the underlying Mathematica expression. You refer to
Cell expression, but this only exists in the FrontEnd. What do you mean by that?$endgroup$
– Somos
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
In the Front End
I assume you have this typed in a Cell in the front-end. That's the only case in which preserving indentation makes sense at the parse step. If that's the case you need simply to get the Cell expression and pass it to:
MathLink`CallFrontEnd[ExportPacket[cellExpr, "InputText"]][[1]]
If you have the CellObject and need the Cell expression you do that via NotebookRead.
If you need the CellObject you'll probably find that easiest via NextCell and PreviousCell
Regenerating Indentation
If you don't have this in the FE and you'd like to regenerate indentation you can do that as I discuss here
$endgroup$
$begingroup$
Thank it works but it seems to be adding extra spaces and newlines where they were not in the original input cell.
$endgroup$
– user13892
7 hours ago
$begingroup$
This is the output it produced for me. Its not a big deal I can clean it up with some regex but if it can literally get the input without any modification that would be ideal."If[Length[$ScriptCommandLine] == 1,rn tPrint["No expressions were given to square."],rn trn targs = Rest[$ScriptCommandLine];rn tsquares = rn Quiet @ Map[rn Replace[ToExpression[#], {$Failed :> ToString[#, InputForm]^2, rn x_ :> x^2}] &, args];rn tMapThread[rn Print["The square of ", #1, " is ", #2, "."] &, {args, squares}]rn ]"
$endgroup$
– user13892
7 hours ago
$begingroup$
Compare this with the output I am expecting."If[Length[$ScriptCommandLine]==1,ntPrint["No expressions were given to square."],ntntargs = Rest[$ScriptCommandLine];ntsquares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];ntMapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]n]"
$endgroup$
– user13892
7 hours ago
$begingroup$
DoesExportPackethave some options other than"InputText"that can get the input text without any interpretation or modification? These functions don't seem to be documented.
$endgroup$
– user13892
7 hours ago
$begingroup$
@user13892 the issue is thePageWidthsetting. Try stuff with that.
$endgroup$
– b3m2a1
7 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f195762%2fis-there-a-way-to-convert-wolfram-language-expression-to-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
In the Front End
I assume you have this typed in a Cell in the front-end. That's the only case in which preserving indentation makes sense at the parse step. If that's the case you need simply to get the Cell expression and pass it to:
MathLink`CallFrontEnd[ExportPacket[cellExpr, "InputText"]][[1]]
If you have the CellObject and need the Cell expression you do that via NotebookRead.
If you need the CellObject you'll probably find that easiest via NextCell and PreviousCell
Regenerating Indentation
If you don't have this in the FE and you'd like to regenerate indentation you can do that as I discuss here
$endgroup$
$begingroup$
Thank it works but it seems to be adding extra spaces and newlines where they were not in the original input cell.
$endgroup$
– user13892
7 hours ago
$begingroup$
This is the output it produced for me. Its not a big deal I can clean it up with some regex but if it can literally get the input without any modification that would be ideal."If[Length[$ScriptCommandLine] == 1,rn tPrint["No expressions were given to square."],rn trn targs = Rest[$ScriptCommandLine];rn tsquares = rn Quiet @ Map[rn Replace[ToExpression[#], {$Failed :> ToString[#, InputForm]^2, rn x_ :> x^2}] &, args];rn tMapThread[rn Print["The square of ", #1, " is ", #2, "."] &, {args, squares}]rn ]"
$endgroup$
– user13892
7 hours ago
$begingroup$
Compare this with the output I am expecting."If[Length[$ScriptCommandLine]==1,ntPrint["No expressions were given to square."],ntntargs = Rest[$ScriptCommandLine];ntsquares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];ntMapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]n]"
$endgroup$
– user13892
7 hours ago
$begingroup$
DoesExportPackethave some options other than"InputText"that can get the input text without any interpretation or modification? These functions don't seem to be documented.
$endgroup$
– user13892
7 hours ago
$begingroup$
@user13892 the issue is thePageWidthsetting. Try stuff with that.
$endgroup$
– b3m2a1
7 hours ago
add a comment |
$begingroup$
In the Front End
I assume you have this typed in a Cell in the front-end. That's the only case in which preserving indentation makes sense at the parse step. If that's the case you need simply to get the Cell expression and pass it to:
MathLink`CallFrontEnd[ExportPacket[cellExpr, "InputText"]][[1]]
If you have the CellObject and need the Cell expression you do that via NotebookRead.
If you need the CellObject you'll probably find that easiest via NextCell and PreviousCell
Regenerating Indentation
If you don't have this in the FE and you'd like to regenerate indentation you can do that as I discuss here
$endgroup$
$begingroup$
Thank it works but it seems to be adding extra spaces and newlines where they were not in the original input cell.
$endgroup$
– user13892
7 hours ago
$begingroup$
This is the output it produced for me. Its not a big deal I can clean it up with some regex but if it can literally get the input without any modification that would be ideal."If[Length[$ScriptCommandLine] == 1,rn tPrint["No expressions were given to square."],rn trn targs = Rest[$ScriptCommandLine];rn tsquares = rn Quiet @ Map[rn Replace[ToExpression[#], {$Failed :> ToString[#, InputForm]^2, rn x_ :> x^2}] &, args];rn tMapThread[rn Print["The square of ", #1, " is ", #2, "."] &, {args, squares}]rn ]"
$endgroup$
– user13892
7 hours ago
$begingroup$
Compare this with the output I am expecting."If[Length[$ScriptCommandLine]==1,ntPrint["No expressions were given to square."],ntntargs = Rest[$ScriptCommandLine];ntsquares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];ntMapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]n]"
$endgroup$
– user13892
7 hours ago
$begingroup$
DoesExportPackethave some options other than"InputText"that can get the input text without any interpretation or modification? These functions don't seem to be documented.
$endgroup$
– user13892
7 hours ago
$begingroup$
@user13892 the issue is thePageWidthsetting. Try stuff with that.
$endgroup$
– b3m2a1
7 hours ago
add a comment |
$begingroup$
In the Front End
I assume you have this typed in a Cell in the front-end. That's the only case in which preserving indentation makes sense at the parse step. If that's the case you need simply to get the Cell expression and pass it to:
MathLink`CallFrontEnd[ExportPacket[cellExpr, "InputText"]][[1]]
If you have the CellObject and need the Cell expression you do that via NotebookRead.
If you need the CellObject you'll probably find that easiest via NextCell and PreviousCell
Regenerating Indentation
If you don't have this in the FE and you'd like to regenerate indentation you can do that as I discuss here
$endgroup$
In the Front End
I assume you have this typed in a Cell in the front-end. That's the only case in which preserving indentation makes sense at the parse step. If that's the case you need simply to get the Cell expression and pass it to:
MathLink`CallFrontEnd[ExportPacket[cellExpr, "InputText"]][[1]]
If you have the CellObject and need the Cell expression you do that via NotebookRead.
If you need the CellObject you'll probably find that easiest via NextCell and PreviousCell
Regenerating Indentation
If you don't have this in the FE and you'd like to regenerate indentation you can do that as I discuss here
answered 8 hours ago
b3m2a1b3m2a1
29.2k360167
29.2k360167
$begingroup$
Thank it works but it seems to be adding extra spaces and newlines where they were not in the original input cell.
$endgroup$
– user13892
7 hours ago
$begingroup$
This is the output it produced for me. Its not a big deal I can clean it up with some regex but if it can literally get the input without any modification that would be ideal."If[Length[$ScriptCommandLine] == 1,rn tPrint["No expressions were given to square."],rn trn targs = Rest[$ScriptCommandLine];rn tsquares = rn Quiet @ Map[rn Replace[ToExpression[#], {$Failed :> ToString[#, InputForm]^2, rn x_ :> x^2}] &, args];rn tMapThread[rn Print["The square of ", #1, " is ", #2, "."] &, {args, squares}]rn ]"
$endgroup$
– user13892
7 hours ago
$begingroup$
Compare this with the output I am expecting."If[Length[$ScriptCommandLine]==1,ntPrint["No expressions were given to square."],ntntargs = Rest[$ScriptCommandLine];ntsquares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];ntMapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]n]"
$endgroup$
– user13892
7 hours ago
$begingroup$
DoesExportPackethave some options other than"InputText"that can get the input text without any interpretation or modification? These functions don't seem to be documented.
$endgroup$
– user13892
7 hours ago
$begingroup$
@user13892 the issue is thePageWidthsetting. Try stuff with that.
$endgroup$
– b3m2a1
7 hours ago
add a comment |
$begingroup$
Thank it works but it seems to be adding extra spaces and newlines where they were not in the original input cell.
$endgroup$
– user13892
7 hours ago
$begingroup$
This is the output it produced for me. Its not a big deal I can clean it up with some regex but if it can literally get the input without any modification that would be ideal."If[Length[$ScriptCommandLine] == 1,rn tPrint["No expressions were given to square."],rn trn targs = Rest[$ScriptCommandLine];rn tsquares = rn Quiet @ Map[rn Replace[ToExpression[#], {$Failed :> ToString[#, InputForm]^2, rn x_ :> x^2}] &, args];rn tMapThread[rn Print["The square of ", #1, " is ", #2, "."] &, {args, squares}]rn ]"
$endgroup$
– user13892
7 hours ago
$begingroup$
Compare this with the output I am expecting."If[Length[$ScriptCommandLine]==1,ntPrint["No expressions were given to square."],ntntargs = Rest[$ScriptCommandLine];ntsquares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];ntMapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]n]"
$endgroup$
– user13892
7 hours ago
$begingroup$
DoesExportPackethave some options other than"InputText"that can get the input text without any interpretation or modification? These functions don't seem to be documented.
$endgroup$
– user13892
7 hours ago
$begingroup$
@user13892 the issue is thePageWidthsetting. Try stuff with that.
$endgroup$
– b3m2a1
7 hours ago
$begingroup$
Thank it works but it seems to be adding extra spaces and newlines where they were not in the original input cell.
$endgroup$
– user13892
7 hours ago
$begingroup$
Thank it works but it seems to be adding extra spaces and newlines where they were not in the original input cell.
$endgroup$
– user13892
7 hours ago
$begingroup$
This is the output it produced for me. Its not a big deal I can clean it up with some regex but if it can literally get the input without any modification that would be ideal.
"If[Length[$ScriptCommandLine] == 1,rn tPrint["No expressions were given to square."],rn trn targs = Rest[$ScriptCommandLine];rn tsquares = rn Quiet @ Map[rn Replace[ToExpression[#], {$Failed :> ToString[#, InputForm]^2, rn x_ :> x^2}] &, args];rn tMapThread[rn Print["The square of ", #1, " is ", #2, "."] &, {args, squares}]rn ]"$endgroup$
– user13892
7 hours ago
$begingroup$
This is the output it produced for me. Its not a big deal I can clean it up with some regex but if it can literally get the input without any modification that would be ideal.
"If[Length[$ScriptCommandLine] == 1,rn tPrint["No expressions were given to square."],rn trn targs = Rest[$ScriptCommandLine];rn tsquares = rn Quiet @ Map[rn Replace[ToExpression[#], {$Failed :> ToString[#, InputForm]^2, rn x_ :> x^2}] &, args];rn tMapThread[rn Print["The square of ", #1, " is ", #2, "."] &, {args, squares}]rn ]"$endgroup$
– user13892
7 hours ago
$begingroup$
Compare this with the output I am expecting.
"If[Length[$ScriptCommandLine]==1,ntPrint["No expressions were given to square."],ntntargs = Rest[$ScriptCommandLine];ntsquares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];ntMapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]n]"$endgroup$
– user13892
7 hours ago
$begingroup$
Compare this with the output I am expecting.
"If[Length[$ScriptCommandLine]==1,ntPrint["No expressions were given to square."],ntntargs = Rest[$ScriptCommandLine];ntsquares = Quiet @ Map[Replace[ToExpression[#], {$Failed:>ToString[#,InputForm]^2, x_ :> x^2}]&, args];ntMapThread[Print["The square of ", #1, " is ", #2, "."]&, {args, squares}]n]"$endgroup$
– user13892
7 hours ago
$begingroup$
Does
ExportPacket have some options other than "InputText" that can get the input text without any interpretation or modification? These functions don't seem to be documented.$endgroup$
– user13892
7 hours ago
$begingroup$
Does
ExportPacket have some options other than "InputText" that can get the input text without any interpretation or modification? These functions don't seem to be documented.$endgroup$
– user13892
7 hours ago
$begingroup$
@user13892 the issue is the
PageWidth setting. Try stuff with that.$endgroup$
– b3m2a1
7 hours ago
$begingroup$
@user13892 the issue is the
PageWidth setting. Try stuff with that.$endgroup$
– b3m2a1
7 hours ago
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f195762%2fis-there-a-way-to-convert-wolfram-language-expression-to-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
ToStringdoes this.$endgroup$
– Roman
8 hours ago
$begingroup$
Something like this?
StringReplace[ToString[Defer[2 + 2]], "Defer[" ~~ x___ ~~ "]" :> x]$endgroup$
– user6014
8 hours ago
$begingroup$
Why exactly do you want to do this? What will you do with the string? Why is indentation important? The indentations are not part of the underlying Mathematica expression. You refer to
Cellexpression, but this only exists in the FrontEnd. What do you mean by that?$endgroup$
– Somos
8 hours ago