Remove backslash from string
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I am defining a new command, where the input contains backslash, which is to be removed later, hence I am searching for a way to accomplish that. The following example removes backslash when it is in-front of the string, but fails when the slash is in-between a string.
documentclassarticle
makeatletter
newcommandremoveabs[1]%
ifcatrelaxnoexpand#1%
expandafterexpandafterexpandafter@gobbleexpandafterstring
fi
#1%
makeatother
begindocument
removeabsthe slash is removed here
removeabsbut not here
enddocument
Does anybody know how to remove the backslash, even if it is in-between a string ?
macros
add a comment |Â
up vote
2
down vote
favorite
I am defining a new command, where the input contains backslash, which is to be removed later, hence I am searching for a way to accomplish that. The following example removes backslash when it is in-front of the string, but fails when the slash is in-between a string.
documentclassarticle
makeatletter
newcommandremoveabs[1]%
ifcatrelaxnoexpand#1%
expandafterexpandafterexpandafter@gobbleexpandafterstring
fi
#1%
makeatother
begindocument
removeabsthe slash is removed here
removeabsbut not here
enddocument
Does anybody know how to remove the backslash, even if it is in-between a string ?
macros
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am defining a new command, where the input contains backslash, which is to be removed later, hence I am searching for a way to accomplish that. The following example removes backslash when it is in-front of the string, but fails when the slash is in-between a string.
documentclassarticle
makeatletter
newcommandremoveabs[1]%
ifcatrelaxnoexpand#1%
expandafterexpandafterexpandafter@gobbleexpandafterstring
fi
#1%
makeatother
begindocument
removeabsthe slash is removed here
removeabsbut not here
enddocument
Does anybody know how to remove the backslash, even if it is in-between a string ?
macros
I am defining a new command, where the input contains backslash, which is to be removed later, hence I am searching for a way to accomplish that. The following example removes backslash when it is in-front of the string, but fails when the slash is in-between a string.
documentclassarticle
makeatletter
newcommandremoveabs[1]%
ifcatrelaxnoexpand#1%
expandafterexpandafterexpandafter@gobbleexpandafterstring
fi
#1%
makeatother
begindocument
removeabsthe slash is removed here
removeabsbut not here
enddocument
Does anybody know how to remove the backslash, even if it is in-between a string ?
macros
macros
edited 1 hour ago
asked 1 hour ago
Ashok
310111
310111
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
documentclassarticle
newcommandremoveabs[1]%
%catcode92=9 endlinechar-1 scantokensexpandafterdetokenize#1%
catcode92=9 endlinechar-1 scantokens#1%
begindocument
removeabsthe slash is removed here
removeabsand also here+++
enddocument
But your use case is not really known...
As pointed out by @A.Ellett there is no real need for detokenize
. Even, maybe you want to preserve things like math:
documentclassarticle
newcommandremoveabs[1]%
catcode92=9 endlinechar-1 scantokens#1%
begindocument
removeabsthe slash $E=mc^2$ is removed here
removeabsand also here+++
enddocument
Perhaps you want to store in macro, the following shows how to do it (but the x
here is used and discarded).
Notice though that therein you should not be some active character with a definition not compatible with an edef
. The ~
and the UTF-8 things are OK.
documentclassarticle
usepackage[T1]fontenc
newcommandremoveabs[1]%
catcode92=9 endlinechar-1 everyeofnoexpandedefxscantokens#1x%
begindocument
removeabsthe slash $E=mc^2$ is~~~~removed here
removeabsand also éééé here+++
enddocument
Thanks to @A.Ellett!
2
Isdetokenize
really necessary there? Won'tscantokens
alone handle everything?
â A.Ellett
52 mins ago
1
@A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
â jfbu
43 mins ago
add a comment |Â
up vote
0
down vote
With expl3
:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandremovebsm
tl_set:Nn l_tmpa_tl #1
regex_replace_all:nnN cC. ccs_to_str:N l_tmpa_tl
tl_use:N l_tmpa_tl
ExplSyntaxOff
begindocument
removebsthe slash is removed here
removebsthe slashes are removed here
removebsand also here
enddocument
Note that the space after the
in the first case doesn't disappear, because it was ignored to begin with.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
documentclassarticle
newcommandremoveabs[1]%
%catcode92=9 endlinechar-1 scantokensexpandafterdetokenize#1%
catcode92=9 endlinechar-1 scantokens#1%
begindocument
removeabsthe slash is removed here
removeabsand also here+++
enddocument
But your use case is not really known...
As pointed out by @A.Ellett there is no real need for detokenize
. Even, maybe you want to preserve things like math:
documentclassarticle
newcommandremoveabs[1]%
catcode92=9 endlinechar-1 scantokens#1%
begindocument
removeabsthe slash $E=mc^2$ is removed here
removeabsand also here+++
enddocument
Perhaps you want to store in macro, the following shows how to do it (but the x
here is used and discarded).
Notice though that therein you should not be some active character with a definition not compatible with an edef
. The ~
and the UTF-8 things are OK.
documentclassarticle
usepackage[T1]fontenc
newcommandremoveabs[1]%
catcode92=9 endlinechar-1 everyeofnoexpandedefxscantokens#1x%
begindocument
removeabsthe slash $E=mc^2$ is~~~~removed here
removeabsand also éééé here+++
enddocument
Thanks to @A.Ellett!
2
Isdetokenize
really necessary there? Won'tscantokens
alone handle everything?
â A.Ellett
52 mins ago
1
@A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
â jfbu
43 mins ago
add a comment |Â
up vote
4
down vote
accepted
documentclassarticle
newcommandremoveabs[1]%
%catcode92=9 endlinechar-1 scantokensexpandafterdetokenize#1%
catcode92=9 endlinechar-1 scantokens#1%
begindocument
removeabsthe slash is removed here
removeabsand also here+++
enddocument
But your use case is not really known...
As pointed out by @A.Ellett there is no real need for detokenize
. Even, maybe you want to preserve things like math:
documentclassarticle
newcommandremoveabs[1]%
catcode92=9 endlinechar-1 scantokens#1%
begindocument
removeabsthe slash $E=mc^2$ is removed here
removeabsand also here+++
enddocument
Perhaps you want to store in macro, the following shows how to do it (but the x
here is used and discarded).
Notice though that therein you should not be some active character with a definition not compatible with an edef
. The ~
and the UTF-8 things are OK.
documentclassarticle
usepackage[T1]fontenc
newcommandremoveabs[1]%
catcode92=9 endlinechar-1 everyeofnoexpandedefxscantokens#1x%
begindocument
removeabsthe slash $E=mc^2$ is~~~~removed here
removeabsand also éééé here+++
enddocument
Thanks to @A.Ellett!
2
Isdetokenize
really necessary there? Won'tscantokens
alone handle everything?
â A.Ellett
52 mins ago
1
@A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
â jfbu
43 mins ago
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
documentclassarticle
newcommandremoveabs[1]%
%catcode92=9 endlinechar-1 scantokensexpandafterdetokenize#1%
catcode92=9 endlinechar-1 scantokens#1%
begindocument
removeabsthe slash is removed here
removeabsand also here+++
enddocument
But your use case is not really known...
As pointed out by @A.Ellett there is no real need for detokenize
. Even, maybe you want to preserve things like math:
documentclassarticle
newcommandremoveabs[1]%
catcode92=9 endlinechar-1 scantokens#1%
begindocument
removeabsthe slash $E=mc^2$ is removed here
removeabsand also here+++
enddocument
Perhaps you want to store in macro, the following shows how to do it (but the x
here is used and discarded).
Notice though that therein you should not be some active character with a definition not compatible with an edef
. The ~
and the UTF-8 things are OK.
documentclassarticle
usepackage[T1]fontenc
newcommandremoveabs[1]%
catcode92=9 endlinechar-1 everyeofnoexpandedefxscantokens#1x%
begindocument
removeabsthe slash $E=mc^2$ is~~~~removed here
removeabsand also éééé here+++
enddocument
Thanks to @A.Ellett!
documentclassarticle
newcommandremoveabs[1]%
%catcode92=9 endlinechar-1 scantokensexpandafterdetokenize#1%
catcode92=9 endlinechar-1 scantokens#1%
begindocument
removeabsthe slash is removed here
removeabsand also here+++
enddocument
But your use case is not really known...
As pointed out by @A.Ellett there is no real need for detokenize
. Even, maybe you want to preserve things like math:
documentclassarticle
newcommandremoveabs[1]%
catcode92=9 endlinechar-1 scantokens#1%
begindocument
removeabsthe slash $E=mc^2$ is removed here
removeabsand also here+++
enddocument
Perhaps you want to store in macro, the following shows how to do it (but the x
here is used and discarded).
Notice though that therein you should not be some active character with a definition not compatible with an edef
. The ~
and the UTF-8 things are OK.
documentclassarticle
usepackage[T1]fontenc
newcommandremoveabs[1]%
catcode92=9 endlinechar-1 everyeofnoexpandedefxscantokens#1x%
begindocument
removeabsthe slash $E=mc^2$ is~~~~removed here
removeabsand also éééé here+++
enddocument
Thanks to @A.Ellett!
edited 36 mins ago
answered 1 hour ago
jfbu
42.8k64139
42.8k64139
2
Isdetokenize
really necessary there? Won'tscantokens
alone handle everything?
â A.Ellett
52 mins ago
1
@A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
â jfbu
43 mins ago
add a comment |Â
2
Isdetokenize
really necessary there? Won'tscantokens
alone handle everything?
â A.Ellett
52 mins ago
1
@A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
â jfbu
43 mins ago
2
2
Is
detokenize
really necessary there? Won't scantokens
alone handle everything?â A.Ellett
52 mins ago
Is
detokenize
really necessary there? Won't scantokens
alone handle everything?â A.Ellett
52 mins ago
1
1
@A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
â jfbu
43 mins ago
@A.Ellett you are absolutely right, but the OP was mentioning "strings"... I will edit.
â jfbu
43 mins ago
add a comment |Â
up vote
0
down vote
With expl3
:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandremovebsm
tl_set:Nn l_tmpa_tl #1
regex_replace_all:nnN cC. ccs_to_str:N l_tmpa_tl
tl_use:N l_tmpa_tl
ExplSyntaxOff
begindocument
removebsthe slash is removed here
removebsthe slashes are removed here
removebsand also here
enddocument
Note that the space after the
in the first case doesn't disappear, because it was ignored to begin with.
add a comment |Â
up vote
0
down vote
With expl3
:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandremovebsm
tl_set:Nn l_tmpa_tl #1
regex_replace_all:nnN cC. ccs_to_str:N l_tmpa_tl
tl_use:N l_tmpa_tl
ExplSyntaxOff
begindocument
removebsthe slash is removed here
removebsthe slashes are removed here
removebsand also here
enddocument
Note that the space after the
in the first case doesn't disappear, because it was ignored to begin with.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
With expl3
:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandremovebsm
tl_set:Nn l_tmpa_tl #1
regex_replace_all:nnN cC. ccs_to_str:N l_tmpa_tl
tl_use:N l_tmpa_tl
ExplSyntaxOff
begindocument
removebsthe slash is removed here
removebsthe slashes are removed here
removebsand also here
enddocument
Note that the space after the
in the first case doesn't disappear, because it was ignored to begin with.
With expl3
:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandremovebsm
tl_set:Nn l_tmpa_tl #1
regex_replace_all:nnN cC. ccs_to_str:N l_tmpa_tl
tl_use:N l_tmpa_tl
ExplSyntaxOff
begindocument
removebsthe slash is removed here
removebsthe slashes are removed here
removebsand also here
enddocument
Note that the space after the
in the first case doesn't disappear, because it was ignored to begin with.
answered 13 mins ago
egreg
688k8518323080
688k8518323080
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f454641%2fremove-backslash-from-string%23new-answer', 'question_page');
);
Post as a guest
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
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
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