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;








4















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.










share|improve this question
























  • What about numbers with more than 8 digits?

    – Marijn
    Aug 13 at 12:15

















4















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.










share|improve this question
























  • What about numbers with more than 8 digits?

    – Marijn
    Aug 13 at 12:15













4












4








4








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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










2 Answers
2






active

oldest

votes


















7















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:



enter image description here






share|improve this answer



























  • 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












  • @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











  • 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



















2















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


enter image description here



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.






share|improve this answer



























    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
    );



    );













    draft saved

    draft discarded


















    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









    7















    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:



    enter image description here






    share|improve this answer



























    • 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












    • @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











    • 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
















    7















    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:



    enter image description here






    share|improve this answer



























    • 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












    • @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











    • 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














    7














    7










    7









    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:



    enter image description here






    share|improve this answer















    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:



    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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 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












    • @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











    • 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


















    • 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












    • @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











    • 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

















    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














    2















    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


    enter image description here



    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.






    share|improve this answer





























      2















      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


      enter image description here



      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.






      share|improve this answer



























        2














        2










        2









        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


        enter image description here



        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.






        share|improve this answer













        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


        enter image description here



        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 13 at 17:30









        egregegreg

        764k90 gold badges1997 silver badges3345 bronze badges




        764k90 gold badges1997 silver badges3345 bronze badges






























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form