Split phone numbers into groups based on first digitInserting an A1 image into an A4 document whilst maintaining page numbers?How to add spaces at every X digit in a binary or hexadecimal number?Header, dots in split equation and parentheses around footnote numbersSplit listing into multiple sectionsTransforming numbers in a matrix structure into color squares
Anyone else seeing white rings in the Undead parish?
Was the Boeing 2707 design flawed?
What stops you from using fixed income in developing countries?
I don't have the theoretical background in my PhD topic. I can't justify getting the degree
How do proponents of Sola Scriptura address the ministry of those Apostles who authored no parts of Scripture?
What should come first—characters or plot?
How to obtain a polynomial with these conditions?
Prison offence - trespassing underwood fence
How do I make my image comply with the requirements of this photography competition?
Rent contract say that pets are not allowed. Possible repercussions if bringing the pet anyway?
What is a natural problem in theory of computation?
When calculating a force, why do I get different result when I try to calculate via torque vs via sum of forces at an axis?
Handling Disruptive Student on the Autism Spectrum
Are game port joystick buttons ever more than plain switches? Is this one just faulty?
Movie where people enter a church but find they can't leave, not in English
Evaluated vs. unevaluated Association
"There were either twelve sexes or none."
Why do banks “park” their money at the European Central Bank?
Changing JPEG to RAW to use on Lightroom?
Hangman game in Python - need feedback on the quality of code
Server Integrity Check CheckCommands question
Is gzip atomic?
How does the OS tell whether an "Address is already in use"?
Can RMSE and MAE have the same value?
Split phone numbers into groups based on first digit
Inserting an A1 image into an A4 document whilst maintaining page numbers?How to add spaces at every X digit in a binary or hexadecimal number?Header, dots in split equation and parentheses around footnote numbersSplit listing into multiple sectionsTransforming numbers in a matrix structure into color squares
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Problem
I am trying to split some numbers based on some very simple criteria. Numbers with 8
digits starting with 4, 8 or 9 should be split into digit groups of length 3 2 3
.
Any other digit of length 8 should be split into groups of two.
Numbers with less digits than 8 should not be split into groups.
Examples
- 23 27 60 11 (hard spaces)
- 404 43 033 (hard spaces, 3 2 3)
- 820 43 033 (hard spaces, 3 2 3)
- 909 64 159 (hard spaces)
- 07979 (no spaces)
- 110 (no spaces), 112 (no spaces), 113 (no spaces)
Sorry for the lack of MWE, but I am not quite sure where to start.
formatting number
add a comment |
Problem
I am trying to split some numbers based on some very simple criteria. Numbers with 8
digits starting with 4, 8 or 9 should be split into digit groups of length 3 2 3
.
Any other digit of length 8 should be split into groups of two.
Numbers with less digits than 8 should not be split into groups.
Examples
- 23 27 60 11 (hard spaces)
- 404 43 033 (hard spaces, 3 2 3)
- 820 43 033 (hard spaces, 3 2 3)
- 909 64 159 (hard spaces)
- 07979 (no spaces)
- 110 (no spaces), 112 (no spaces), 113 (no spaces)
Sorry for the lack of MWE, but I am not quite sure where to start.
formatting number
What about numbers with more than 8 digits?
– Marijn
Aug 13 at 12:15
add a comment |
Problem
I am trying to split some numbers based on some very simple criteria. Numbers with 8
digits starting with 4, 8 or 9 should be split into digit groups of length 3 2 3
.
Any other digit of length 8 should be split into groups of two.
Numbers with less digits than 8 should not be split into groups.
Examples
- 23 27 60 11 (hard spaces)
- 404 43 033 (hard spaces, 3 2 3)
- 820 43 033 (hard spaces, 3 2 3)
- 909 64 159 (hard spaces)
- 07979 (no spaces)
- 110 (no spaces), 112 (no spaces), 113 (no spaces)
Sorry for the lack of MWE, but I am not quite sure where to start.
formatting number
Problem
I am trying to split some numbers based on some very simple criteria. Numbers with 8
digits starting with 4, 8 or 9 should be split into digit groups of length 3 2 3
.
Any other digit of length 8 should be split into groups of two.
Numbers with less digits than 8 should not be split into groups.
Examples
- 23 27 60 11 (hard spaces)
- 404 43 033 (hard spaces, 3 2 3)
- 820 43 033 (hard spaces, 3 2 3)
- 909 64 159 (hard spaces)
- 07979 (no spaces)
- 110 (no spaces), 112 (no spaces), 113 (no spaces)
Sorry for the lack of MWE, but I am not quite sure where to start.
formatting number
formatting number
asked Aug 13 at 11:46
N3buchadnezzarN3buchadnezzar
4,8005 gold badges42 silver badges99 bronze badges
4,8005 gold badges42 silver badges99 bronze badges
What about numbers with more than 8 digits?
– Marijn
Aug 13 at 12:15
add a comment |
What about numbers with more than 8 digits?
– Marijn
Aug 13 at 12:15
What about numbers with more than 8 digits?
– Marijn
Aug 13 at 12:15
What about numbers with more than 8 digits?
– Marijn
Aug 13 at 12:15
add a comment |
2 Answers
2
active
oldest
votes
This can be done with the xstring
package, which provides commands for extracting and comparing substrings.
It is possible to do some preprocessing to the string before the formatting is applied, for example to remove whitespace. The xstring
commands for extracting substrings, modifications and counts have the general syntax Commandarg1...[result]
where the optional result
argument stores the result for further processing (if this argument is not given the result is just printed directly). This can be used for preprocessing to store the preprocessed string and do the rest of the processing on the result string.
MWE:
documentclassarticle
newififstartnum
usepackagexstring
newcommandsplitdigits[1]%
StrDel#1 [newstring]%
StrLennewstring[mylen]%
ifnum mylen=8 %
startnumfalse%
IfBeginWithnewstring4startnumtrue%
IfBeginWithnewstring8startnumtrue%
IfBeginWithnewstring9startnumtrue%
ifstartnum%
StrLeftnewstring3 StrMidnewstring45 StrRightnewstring3%
else%
StrLeftnewstring2 StrMidnewstring34 StrMidnewstring56 StrRightnewstring2%
fi%
else%
#1%
fi%
begindocument
noindentsplitdigits23276011\
splitdigits40443033\
splitdigits82043033\
splitdigits90964159\
splitdigits07979\
splitdigits110 splitdigits112 splitdigits113\
splitdigits9 09 6415 9\
splitdigits90 96 41 59\
splitdigits232 76 011
enddocument
Result:
Great answer! Is it possible to also handle inputs such atsplitdigits9 09 6415 9
andsplitdigits90 96 41 59
,splitdigits232 76 011
?
– N3buchadnezzar
Aug 13 at 15:57
@N3buchadnezzar that is possible, you can delete all spaces before you format the numbers usingStrDel
. See page 8 of the manual.
– Marijn
Aug 13 at 16:10
@Marjin Thanks! But I still can not make it work. WritingdefnewnumStrDel400 7519 newnum splitdigitsnewnum
Does not work as it expands too late.
– N3buchadnezzar
Aug 13 at 16:38
@N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.
– Marijn
Aug 13 at 17:02
Thanks a lot, I tried to do as you did but withnewcommandnewstring[1]StrDel#1
is the problem with this approach that the result expands too late?
– N3buchadnezzar
Aug 13 at 17:19
|
show 1 more comment
Branch according to the length of the argument: if it is eight digit long, branch with respect to the first digit; otherwise print the argument.
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewExpandableDocumentCommandphonem
nebu_phone:n #1
cs_new:Nn nebu_phone:n
int_compare:nTF tl_count:n #1 = 8
__nebu_phone_eight:n #1
#1
cs_new:Nn __nebu_phone_eight:n
str_case_e:nnF tl_head:n #1
4 __nebu_phone_iii_ii_iii:nnnnnnnn #1
8 __nebu_phone_iii_ii_iii:nnnnnnnn #1
9 __nebu_phone_iii_ii_iii:nnnnnnnn #1
__nebu_phone_ii:nnnnnnnn #1
cs_new:Nn __nebu_phone_iii_ii_iii:nnnnnnnn #1#2#3nobreakspace#4#5nobreakspace#6#7#8
cs_new:Nn __nebu_phone_ii:nnnnnnnn #1#2nobreakspace#3#4nobreakspace#5#6nobreakspace#7#8
ExplSyntaxOff
begindocument
phone23276011
phone40443033
phone82043033
phone90964159
phone07979
phone110, phone112, phone113
enddocument
If you want to remove spaces from the input, you have to give up expandability:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandphonem
nebu_phone:n #1
tl_new:N l__nebu_phone_tl
cs_new_protected:Nn nebu_phone:n
tl_set:Nn l__nebu_phone_tl #1
tl_remove_all:Nn l__nebu_phone_tl ~
int_compare:nTF tl_count:N l__nebu_phone_tl = 8
__nebu_phone_eight:V l__nebu_phone_tl
tl_use:N l__nebu_phone_tl
cs_new:Nn __nebu_phone_eight:n
str_case_e:nnF tl_head:n #1
4 __nebu_phone_iii_ii_iii:nnnnnnnn #1
8 __nebu_phone_iii_ii_iii:nnnnnnnn #1
9 __nebu_phone_iii_ii_iii:nnnnnnnn #1
__nebu_phone_ii:nnnnnnnn #1
cs_generate_variant:Nn __nebu_phone_eight:n V
cs_new:Nn __nebu_phone_iii_ii_iii:nnnnnnnn #1#2#3nobreakspace#4#5nobreakspace#6#7#8
cs_new:Nn __nebu_phone_ii:nnnnnnnn #1#2nobreakspace#3#4nobreakspace#5#6nobreakspace#7#8
ExplSyntaxOff
begindocument
phone232 76 011
phone40 44 30 33
phone820 430 33
phone90964159
phone079 79
phone110, phone112, phone113
enddocument
The output is the same.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
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%2ftex.stackexchange.com%2fquestions%2f504040%2fsplit-phone-numbers-into-groups-based-on-first-digit%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This can be done with the xstring
package, which provides commands for extracting and comparing substrings.
It is possible to do some preprocessing to the string before the formatting is applied, for example to remove whitespace. The xstring
commands for extracting substrings, modifications and counts have the general syntax Commandarg1...[result]
where the optional result
argument stores the result for further processing (if this argument is not given the result is just printed directly). This can be used for preprocessing to store the preprocessed string and do the rest of the processing on the result string.
MWE:
documentclassarticle
newififstartnum
usepackagexstring
newcommandsplitdigits[1]%
StrDel#1 [newstring]%
StrLennewstring[mylen]%
ifnum mylen=8 %
startnumfalse%
IfBeginWithnewstring4startnumtrue%
IfBeginWithnewstring8startnumtrue%
IfBeginWithnewstring9startnumtrue%
ifstartnum%
StrLeftnewstring3 StrMidnewstring45 StrRightnewstring3%
else%
StrLeftnewstring2 StrMidnewstring34 StrMidnewstring56 StrRightnewstring2%
fi%
else%
#1%
fi%
begindocument
noindentsplitdigits23276011\
splitdigits40443033\
splitdigits82043033\
splitdigits90964159\
splitdigits07979\
splitdigits110 splitdigits112 splitdigits113\
splitdigits9 09 6415 9\
splitdigits90 96 41 59\
splitdigits232 76 011
enddocument
Result:
Great answer! Is it possible to also handle inputs such atsplitdigits9 09 6415 9
andsplitdigits90 96 41 59
,splitdigits232 76 011
?
– N3buchadnezzar
Aug 13 at 15:57
@N3buchadnezzar that is possible, you can delete all spaces before you format the numbers usingStrDel
. See page 8 of the manual.
– Marijn
Aug 13 at 16:10
@Marjin Thanks! But I still can not make it work. WritingdefnewnumStrDel400 7519 newnum splitdigitsnewnum
Does not work as it expands too late.
– N3buchadnezzar
Aug 13 at 16:38
@N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.
– Marijn
Aug 13 at 17:02
Thanks a lot, I tried to do as you did but withnewcommandnewstring[1]StrDel#1
is the problem with this approach that the result expands too late?
– N3buchadnezzar
Aug 13 at 17:19
|
show 1 more comment
This can be done with the xstring
package, which provides commands for extracting and comparing substrings.
It is possible to do some preprocessing to the string before the formatting is applied, for example to remove whitespace. The xstring
commands for extracting substrings, modifications and counts have the general syntax Commandarg1...[result]
where the optional result
argument stores the result for further processing (if this argument is not given the result is just printed directly). This can be used for preprocessing to store the preprocessed string and do the rest of the processing on the result string.
MWE:
documentclassarticle
newififstartnum
usepackagexstring
newcommandsplitdigits[1]%
StrDel#1 [newstring]%
StrLennewstring[mylen]%
ifnum mylen=8 %
startnumfalse%
IfBeginWithnewstring4startnumtrue%
IfBeginWithnewstring8startnumtrue%
IfBeginWithnewstring9startnumtrue%
ifstartnum%
StrLeftnewstring3 StrMidnewstring45 StrRightnewstring3%
else%
StrLeftnewstring2 StrMidnewstring34 StrMidnewstring56 StrRightnewstring2%
fi%
else%
#1%
fi%
begindocument
noindentsplitdigits23276011\
splitdigits40443033\
splitdigits82043033\
splitdigits90964159\
splitdigits07979\
splitdigits110 splitdigits112 splitdigits113\
splitdigits9 09 6415 9\
splitdigits90 96 41 59\
splitdigits232 76 011
enddocument
Result:
Great answer! Is it possible to also handle inputs such atsplitdigits9 09 6415 9
andsplitdigits90 96 41 59
,splitdigits232 76 011
?
– N3buchadnezzar
Aug 13 at 15:57
@N3buchadnezzar that is possible, you can delete all spaces before you format the numbers usingStrDel
. See page 8 of the manual.
– Marijn
Aug 13 at 16:10
@Marjin Thanks! But I still can not make it work. WritingdefnewnumStrDel400 7519 newnum splitdigitsnewnum
Does not work as it expands too late.
– N3buchadnezzar
Aug 13 at 16:38
@N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.
– Marijn
Aug 13 at 17:02
Thanks a lot, I tried to do as you did but withnewcommandnewstring[1]StrDel#1
is the problem with this approach that the result expands too late?
– N3buchadnezzar
Aug 13 at 17:19
|
show 1 more comment
This can be done with the xstring
package, which provides commands for extracting and comparing substrings.
It is possible to do some preprocessing to the string before the formatting is applied, for example to remove whitespace. The xstring
commands for extracting substrings, modifications and counts have the general syntax Commandarg1...[result]
where the optional result
argument stores the result for further processing (if this argument is not given the result is just printed directly). This can be used for preprocessing to store the preprocessed string and do the rest of the processing on the result string.
MWE:
documentclassarticle
newififstartnum
usepackagexstring
newcommandsplitdigits[1]%
StrDel#1 [newstring]%
StrLennewstring[mylen]%
ifnum mylen=8 %
startnumfalse%
IfBeginWithnewstring4startnumtrue%
IfBeginWithnewstring8startnumtrue%
IfBeginWithnewstring9startnumtrue%
ifstartnum%
StrLeftnewstring3 StrMidnewstring45 StrRightnewstring3%
else%
StrLeftnewstring2 StrMidnewstring34 StrMidnewstring56 StrRightnewstring2%
fi%
else%
#1%
fi%
begindocument
noindentsplitdigits23276011\
splitdigits40443033\
splitdigits82043033\
splitdigits90964159\
splitdigits07979\
splitdigits110 splitdigits112 splitdigits113\
splitdigits9 09 6415 9\
splitdigits90 96 41 59\
splitdigits232 76 011
enddocument
Result:
This can be done with the xstring
package, which provides commands for extracting and comparing substrings.
It is possible to do some preprocessing to the string before the formatting is applied, for example to remove whitespace. The xstring
commands for extracting substrings, modifications and counts have the general syntax Commandarg1...[result]
where the optional result
argument stores the result for further processing (if this argument is not given the result is just printed directly). This can be used for preprocessing to store the preprocessed string and do the rest of the processing on the result string.
MWE:
documentclassarticle
newififstartnum
usepackagexstring
newcommandsplitdigits[1]%
StrDel#1 [newstring]%
StrLennewstring[mylen]%
ifnum mylen=8 %
startnumfalse%
IfBeginWithnewstring4startnumtrue%
IfBeginWithnewstring8startnumtrue%
IfBeginWithnewstring9startnumtrue%
ifstartnum%
StrLeftnewstring3 StrMidnewstring45 StrRightnewstring3%
else%
StrLeftnewstring2 StrMidnewstring34 StrMidnewstring56 StrRightnewstring2%
fi%
else%
#1%
fi%
begindocument
noindentsplitdigits23276011\
splitdigits40443033\
splitdigits82043033\
splitdigits90964159\
splitdigits07979\
splitdigits110 splitdigits112 splitdigits113\
splitdigits9 09 6415 9\
splitdigits90 96 41 59\
splitdigits232 76 011
enddocument
Result:
edited Aug 13 at 17:01
answered Aug 13 at 12:38
MarijnMarijn
11.7k1 gold badge6 silver badges40 bronze badges
11.7k1 gold badge6 silver badges40 bronze badges
Great answer! Is it possible to also handle inputs such atsplitdigits9 09 6415 9
andsplitdigits90 96 41 59
,splitdigits232 76 011
?
– N3buchadnezzar
Aug 13 at 15:57
@N3buchadnezzar that is possible, you can delete all spaces before you format the numbers usingStrDel
. See page 8 of the manual.
– Marijn
Aug 13 at 16:10
@Marjin Thanks! But I still can not make it work. WritingdefnewnumStrDel400 7519 newnum splitdigitsnewnum
Does not work as it expands too late.
– N3buchadnezzar
Aug 13 at 16:38
@N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.
– Marijn
Aug 13 at 17:02
Thanks a lot, I tried to do as you did but withnewcommandnewstring[1]StrDel#1
is the problem with this approach that the result expands too late?
– N3buchadnezzar
Aug 13 at 17:19
|
show 1 more comment
Great answer! Is it possible to also handle inputs such atsplitdigits9 09 6415 9
andsplitdigits90 96 41 59
,splitdigits232 76 011
?
– N3buchadnezzar
Aug 13 at 15:57
@N3buchadnezzar that is possible, you can delete all spaces before you format the numbers usingStrDel
. See page 8 of the manual.
– Marijn
Aug 13 at 16:10
@Marjin Thanks! But I still can not make it work. WritingdefnewnumStrDel400 7519 newnum splitdigitsnewnum
Does not work as it expands too late.
– N3buchadnezzar
Aug 13 at 16:38
@N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.
– Marijn
Aug 13 at 17:02
Thanks a lot, I tried to do as you did but withnewcommandnewstring[1]StrDel#1
is the problem with this approach that the result expands too late?
– N3buchadnezzar
Aug 13 at 17:19
Great answer! Is it possible to also handle inputs such at
splitdigits9 09 6415 9
and splitdigits90 96 41 59
, splitdigits232 76 011
?– N3buchadnezzar
Aug 13 at 15:57
Great answer! Is it possible to also handle inputs such at
splitdigits9 09 6415 9
and splitdigits90 96 41 59
, splitdigits232 76 011
?– N3buchadnezzar
Aug 13 at 15:57
@N3buchadnezzar that is possible, you can delete all spaces before you format the numbers using
StrDel
. See page 8 of the manual.– Marijn
Aug 13 at 16:10
@N3buchadnezzar that is possible, you can delete all spaces before you format the numbers using
StrDel
. See page 8 of the manual.– Marijn
Aug 13 at 16:10
@Marjin Thanks! But I still can not make it work. Writing
defnewnumStrDel400 7519 newnum splitdigitsnewnum
Does not work as it expands too late.– N3buchadnezzar
Aug 13 at 16:38
@Marjin Thanks! But I still can not make it work. Writing
defnewnumStrDel400 7519 newnum splitdigitsnewnum
Does not work as it expands too late.– N3buchadnezzar
Aug 13 at 16:38
@N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.
– Marijn
Aug 13 at 17:02
@N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.
– Marijn
Aug 13 at 17:02
Thanks a lot, I tried to do as you did but with
newcommandnewstring[1]StrDel#1
is the problem with this approach that the result expands too late?– N3buchadnezzar
Aug 13 at 17:19
Thanks a lot, I tried to do as you did but with
newcommandnewstring[1]StrDel#1
is the problem with this approach that the result expands too late?– N3buchadnezzar
Aug 13 at 17:19
|
show 1 more comment
Branch according to the length of the argument: if it is eight digit long, branch with respect to the first digit; otherwise print the argument.
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewExpandableDocumentCommandphonem
nebu_phone:n #1
cs_new:Nn nebu_phone:n
int_compare:nTF tl_count:n #1 = 8
__nebu_phone_eight:n #1
#1
cs_new:Nn __nebu_phone_eight:n
str_case_e:nnF tl_head:n #1
4 __nebu_phone_iii_ii_iii:nnnnnnnn #1
8 __nebu_phone_iii_ii_iii:nnnnnnnn #1
9 __nebu_phone_iii_ii_iii:nnnnnnnn #1
__nebu_phone_ii:nnnnnnnn #1
cs_new:Nn __nebu_phone_iii_ii_iii:nnnnnnnn #1#2#3nobreakspace#4#5nobreakspace#6#7#8
cs_new:Nn __nebu_phone_ii:nnnnnnnn #1#2nobreakspace#3#4nobreakspace#5#6nobreakspace#7#8
ExplSyntaxOff
begindocument
phone23276011
phone40443033
phone82043033
phone90964159
phone07979
phone110, phone112, phone113
enddocument
If you want to remove spaces from the input, you have to give up expandability:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandphonem
nebu_phone:n #1
tl_new:N l__nebu_phone_tl
cs_new_protected:Nn nebu_phone:n
tl_set:Nn l__nebu_phone_tl #1
tl_remove_all:Nn l__nebu_phone_tl ~
int_compare:nTF tl_count:N l__nebu_phone_tl = 8
__nebu_phone_eight:V l__nebu_phone_tl
tl_use:N l__nebu_phone_tl
cs_new:Nn __nebu_phone_eight:n
str_case_e:nnF tl_head:n #1
4 __nebu_phone_iii_ii_iii:nnnnnnnn #1
8 __nebu_phone_iii_ii_iii:nnnnnnnn #1
9 __nebu_phone_iii_ii_iii:nnnnnnnn #1
__nebu_phone_ii:nnnnnnnn #1
cs_generate_variant:Nn __nebu_phone_eight:n V
cs_new:Nn __nebu_phone_iii_ii_iii:nnnnnnnn #1#2#3nobreakspace#4#5nobreakspace#6#7#8
cs_new:Nn __nebu_phone_ii:nnnnnnnn #1#2nobreakspace#3#4nobreakspace#5#6nobreakspace#7#8
ExplSyntaxOff
begindocument
phone232 76 011
phone40 44 30 33
phone820 430 33
phone90964159
phone079 79
phone110, phone112, phone113
enddocument
The output is the same.
add a comment |
Branch according to the length of the argument: if it is eight digit long, branch with respect to the first digit; otherwise print the argument.
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewExpandableDocumentCommandphonem
nebu_phone:n #1
cs_new:Nn nebu_phone:n
int_compare:nTF tl_count:n #1 = 8
__nebu_phone_eight:n #1
#1
cs_new:Nn __nebu_phone_eight:n
str_case_e:nnF tl_head:n #1
4 __nebu_phone_iii_ii_iii:nnnnnnnn #1
8 __nebu_phone_iii_ii_iii:nnnnnnnn #1
9 __nebu_phone_iii_ii_iii:nnnnnnnn #1
__nebu_phone_ii:nnnnnnnn #1
cs_new:Nn __nebu_phone_iii_ii_iii:nnnnnnnn #1#2#3nobreakspace#4#5nobreakspace#6#7#8
cs_new:Nn __nebu_phone_ii:nnnnnnnn #1#2nobreakspace#3#4nobreakspace#5#6nobreakspace#7#8
ExplSyntaxOff
begindocument
phone23276011
phone40443033
phone82043033
phone90964159
phone07979
phone110, phone112, phone113
enddocument
If you want to remove spaces from the input, you have to give up expandability:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandphonem
nebu_phone:n #1
tl_new:N l__nebu_phone_tl
cs_new_protected:Nn nebu_phone:n
tl_set:Nn l__nebu_phone_tl #1
tl_remove_all:Nn l__nebu_phone_tl ~
int_compare:nTF tl_count:N l__nebu_phone_tl = 8
__nebu_phone_eight:V l__nebu_phone_tl
tl_use:N l__nebu_phone_tl
cs_new:Nn __nebu_phone_eight:n
str_case_e:nnF tl_head:n #1
4 __nebu_phone_iii_ii_iii:nnnnnnnn #1
8 __nebu_phone_iii_ii_iii:nnnnnnnn #1
9 __nebu_phone_iii_ii_iii:nnnnnnnn #1
__nebu_phone_ii:nnnnnnnn #1
cs_generate_variant:Nn __nebu_phone_eight:n V
cs_new:Nn __nebu_phone_iii_ii_iii:nnnnnnnn #1#2#3nobreakspace#4#5nobreakspace#6#7#8
cs_new:Nn __nebu_phone_ii:nnnnnnnn #1#2nobreakspace#3#4nobreakspace#5#6nobreakspace#7#8
ExplSyntaxOff
begindocument
phone232 76 011
phone40 44 30 33
phone820 430 33
phone90964159
phone079 79
phone110, phone112, phone113
enddocument
The output is the same.
add a comment |
Branch according to the length of the argument: if it is eight digit long, branch with respect to the first digit; otherwise print the argument.
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewExpandableDocumentCommandphonem
nebu_phone:n #1
cs_new:Nn nebu_phone:n
int_compare:nTF tl_count:n #1 = 8
__nebu_phone_eight:n #1
#1
cs_new:Nn __nebu_phone_eight:n
str_case_e:nnF tl_head:n #1
4 __nebu_phone_iii_ii_iii:nnnnnnnn #1
8 __nebu_phone_iii_ii_iii:nnnnnnnn #1
9 __nebu_phone_iii_ii_iii:nnnnnnnn #1
__nebu_phone_ii:nnnnnnnn #1
cs_new:Nn __nebu_phone_iii_ii_iii:nnnnnnnn #1#2#3nobreakspace#4#5nobreakspace#6#7#8
cs_new:Nn __nebu_phone_ii:nnnnnnnn #1#2nobreakspace#3#4nobreakspace#5#6nobreakspace#7#8
ExplSyntaxOff
begindocument
phone23276011
phone40443033
phone82043033
phone90964159
phone07979
phone110, phone112, phone113
enddocument
If you want to remove spaces from the input, you have to give up expandability:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandphonem
nebu_phone:n #1
tl_new:N l__nebu_phone_tl
cs_new_protected:Nn nebu_phone:n
tl_set:Nn l__nebu_phone_tl #1
tl_remove_all:Nn l__nebu_phone_tl ~
int_compare:nTF tl_count:N l__nebu_phone_tl = 8
__nebu_phone_eight:V l__nebu_phone_tl
tl_use:N l__nebu_phone_tl
cs_new:Nn __nebu_phone_eight:n
str_case_e:nnF tl_head:n #1
4 __nebu_phone_iii_ii_iii:nnnnnnnn #1
8 __nebu_phone_iii_ii_iii:nnnnnnnn #1
9 __nebu_phone_iii_ii_iii:nnnnnnnn #1
__nebu_phone_ii:nnnnnnnn #1
cs_generate_variant:Nn __nebu_phone_eight:n V
cs_new:Nn __nebu_phone_iii_ii_iii:nnnnnnnn #1#2#3nobreakspace#4#5nobreakspace#6#7#8
cs_new:Nn __nebu_phone_ii:nnnnnnnn #1#2nobreakspace#3#4nobreakspace#5#6nobreakspace#7#8
ExplSyntaxOff
begindocument
phone232 76 011
phone40 44 30 33
phone820 430 33
phone90964159
phone079 79
phone110, phone112, phone113
enddocument
The output is the same.
Branch according to the length of the argument: if it is eight digit long, branch with respect to the first digit; otherwise print the argument.
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewExpandableDocumentCommandphonem
nebu_phone:n #1
cs_new:Nn nebu_phone:n
int_compare:nTF tl_count:n #1 = 8
__nebu_phone_eight:n #1
#1
cs_new:Nn __nebu_phone_eight:n
str_case_e:nnF tl_head:n #1
4 __nebu_phone_iii_ii_iii:nnnnnnnn #1
8 __nebu_phone_iii_ii_iii:nnnnnnnn #1
9 __nebu_phone_iii_ii_iii:nnnnnnnn #1
__nebu_phone_ii:nnnnnnnn #1
cs_new:Nn __nebu_phone_iii_ii_iii:nnnnnnnn #1#2#3nobreakspace#4#5nobreakspace#6#7#8
cs_new:Nn __nebu_phone_ii:nnnnnnnn #1#2nobreakspace#3#4nobreakspace#5#6nobreakspace#7#8
ExplSyntaxOff
begindocument
phone23276011
phone40443033
phone82043033
phone90964159
phone07979
phone110, phone112, phone113
enddocument
If you want to remove spaces from the input, you have to give up expandability:
documentclassarticle
usepackagexparse
ExplSyntaxOn
NewDocumentCommandphonem
nebu_phone:n #1
tl_new:N l__nebu_phone_tl
cs_new_protected:Nn nebu_phone:n
tl_set:Nn l__nebu_phone_tl #1
tl_remove_all:Nn l__nebu_phone_tl ~
int_compare:nTF tl_count:N l__nebu_phone_tl = 8
__nebu_phone_eight:V l__nebu_phone_tl
tl_use:N l__nebu_phone_tl
cs_new:Nn __nebu_phone_eight:n
str_case_e:nnF tl_head:n #1
4 __nebu_phone_iii_ii_iii:nnnnnnnn #1
8 __nebu_phone_iii_ii_iii:nnnnnnnn #1
9 __nebu_phone_iii_ii_iii:nnnnnnnn #1
__nebu_phone_ii:nnnnnnnn #1
cs_generate_variant:Nn __nebu_phone_eight:n V
cs_new:Nn __nebu_phone_iii_ii_iii:nnnnnnnn #1#2#3nobreakspace#4#5nobreakspace#6#7#8
cs_new:Nn __nebu_phone_ii:nnnnnnnn #1#2nobreakspace#3#4nobreakspace#5#6nobreakspace#7#8
ExplSyntaxOff
begindocument
phone232 76 011
phone40 44 30 33
phone820 430 33
phone90964159
phone079 79
phone110, phone112, phone113
enddocument
The output is the same.
answered Aug 13 at 17:30
egregegreg
764k90 gold badges1997 silver badges3345 bronze badges
764k90 gold badges1997 silver badges3345 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX 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.
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%2ftex.stackexchange.com%2fquestions%2f504040%2fsplit-phone-numbers-into-groups-based-on-first-digit%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
What about numbers with more than 8 digits?
– Marijn
Aug 13 at 12:15