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

In which case does the Security misconfiguration vulnerability apply to?

A torrent of foreign terms

80's/90's superhero cartoon with a man on fire and a man who made ice runways like Frozone

Why aren’t there water shutoff valves for each room?

Should I email my professor about a recommendation letter if he has offered me a job?

Can renaming a method preserve encapsulation?

Can sampling rate be a floating point number?

Why is there a large performance impact when looping over an array over 240 elements?

Boss asked a co-worker to assault me

Generate Brainfuck for the numbers 1–255

How exactly are corporate bonds priced at issue

What to do with a williow tree with a cracked split trunk due to strong winds

Why aren't rockets built with truss structures inside their fuel & oxidizer tanks to increase structural strength?

Word for an event that will likely never happen again

What is the difference between 王 and 皇?

PhD advisor lost funding, need advice

Is this n-speak?

Do I have to cite common CS algorithms?

Can lodestones be used to magnetize crude iron weapons?

Is there any way to stop a user from creating executables and running them?

Is it okay for a ticket seller to grab a tip in the USA?

How to Check all AD userers for "blank" password?

How do I call a 6 digit Austrailian phone number with a US based mobile phone?

Is there a way to count the number of lines of text in a file including non-delimited ones?



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
    11 hours ago

















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
    11 hours ago













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 11 hours ago









N3buchadnezzarN3buchadnezzar

4,7655 gold badges42 silver badges98 bronze badges




4,7655 gold badges42 silver badges98 bronze badges















  • What about numbers with more than 8 digits?

    – Marijn
    11 hours ago

















  • What about numbers with more than 8 digits?

    – Marijn
    11 hours ago
















What about numbers with more than 8 digits?

– Marijn
11 hours ago





What about numbers with more than 8 digits?

– Marijn
11 hours ago










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












  • @N3buchadnezzar that is possible, you can delete all spaces before you format the numbers using StrDel. See page 8 of the manual.

    – Marijn
    7 hours ago












  • @Marjin Thanks! But I still can not make it work. Writing defnewnumStrDel400 7519 newnum splitdigitsnewnum Does not work as it expands too late.

    – N3buchadnezzar
    6 hours ago












  • @N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.

    – Marijn
    6 hours ago











  • 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
    6 hours ago



















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












    • @N3buchadnezzar that is possible, you can delete all spaces before you format the numbers using StrDel. See page 8 of the manual.

      – Marijn
      7 hours ago












    • @Marjin Thanks! But I still can not make it work. Writing defnewnumStrDel400 7519 newnum splitdigitsnewnum Does not work as it expands too late.

      – N3buchadnezzar
      6 hours ago












    • @N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.

      – Marijn
      6 hours ago











    • 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
      6 hours ago
















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












    • @N3buchadnezzar that is possible, you can delete all spaces before you format the numbers using StrDel. See page 8 of the manual.

      – Marijn
      7 hours ago












    • @Marjin Thanks! But I still can not make it work. Writing defnewnumStrDel400 7519 newnum splitdigitsnewnum Does not work as it expands too late.

      – N3buchadnezzar
      6 hours ago












    • @N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.

      – Marijn
      6 hours ago











    • 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
      6 hours ago














    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 6 hours ago

























    answered 10 hours ago









    MarijnMarijn

    11.4k1 gold badge6 silver badges40 bronze badges




    11.4k1 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
      7 hours ago












    • @N3buchadnezzar that is possible, you can delete all spaces before you format the numbers using StrDel. See page 8 of the manual.

      – Marijn
      7 hours ago












    • @Marjin Thanks! But I still can not make it work. Writing defnewnumStrDel400 7519 newnum splitdigitsnewnum Does not work as it expands too late.

      – N3buchadnezzar
      6 hours ago












    • @N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.

      – Marijn
      6 hours ago











    • 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
      6 hours ago


















    • Great answer! Is it possible to also handle inputs such at splitdigits9 09 6415 9 and splitdigits90 96 41 59, splitdigits232 76 011?

      – N3buchadnezzar
      7 hours ago












    • @N3buchadnezzar that is possible, you can delete all spaces before you format the numbers using StrDel. See page 8 of the manual.

      – Marijn
      7 hours ago












    • @Marjin Thanks! But I still can not make it work. Writing defnewnumStrDel400 7519 newnum splitdigitsnewnum Does not work as it expands too late.

      – N3buchadnezzar
      6 hours ago












    • @N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.

      – Marijn
      6 hours ago











    • 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
      6 hours ago

















    Great answer! Is it possible to also handle inputs such at splitdigits9 09 6415 9 and splitdigits90 96 41 59, splitdigits232 76 011?

    – N3buchadnezzar
    7 hours ago






    Great answer! Is it possible to also handle inputs such at splitdigits9 09 6415 9 and splitdigits90 96 41 59, splitdigits232 76 011?

    – N3buchadnezzar
    7 hours ago














    @N3buchadnezzar that is possible, you can delete all spaces before you format the numbers using StrDel. See page 8 of the manual.

    – Marijn
    7 hours ago






    @N3buchadnezzar that is possible, you can delete all spaces before you format the numbers using StrDel. See page 8 of the manual.

    – Marijn
    7 hours ago














    @Marjin Thanks! But I still can not make it work. Writing defnewnumStrDel400 7519 newnum splitdigitsnewnum Does not work as it expands too late.

    – N3buchadnezzar
    6 hours ago






    @Marjin Thanks! But I still can not make it work. Writing defnewnumStrDel400 7519 newnum splitdigitsnewnum Does not work as it expands too late.

    – N3buchadnezzar
    6 hours ago














    @N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.

    – Marijn
    6 hours ago





    @N3buchadnezzar the idea is to do the preprocessing inside of the command, see edit.

    – Marijn
    6 hours ago













    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
    6 hours ago






    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
    6 hours ago














    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 5 hours ago









        egregegreg

        762k90 gold badges1990 silver badges3338 bronze badges




        762k90 gold badges1990 silver badges3338 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

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480