Insert Hyphen after every 4th character in input.

Hi All,

 

I have a requirement, have to separate the string with a Hyphen(-) after every 4th character entered by the use, also it should not count space as string and should ignore it.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    Small correction on vimalkumars (vimal) code. If text is up to 4 character length you don't want hyphen(-), right? Use below code.
    Thanks.


    with(
    local!insertIndex: 4, /*"Insert Hyphen after every 4th character in input."*/
    if(isnull(ri!text), null,
    if(len(ri!text)<5,ri!text, joinarray(
    char(
    insert(
    code(
    ri!text
    ),
    45, /* To Insert Hyphen */
    (
    (
    enumerate(
    quotient(
    len(
    ri!text
    ),
    local!insertIndex
    )
    ) + 1
    ) * local!insertIndex
    ) + 1
    )
    )
    )
    )
    )
    )
Reply
  • 0
    Certified Lead Developer
    Small correction on vimalkumars (vimal) code. If text is up to 4 character length you don't want hyphen(-), right? Use below code.
    Thanks.


    with(
    local!insertIndex: 4, /*"Insert Hyphen after every 4th character in input."*/
    if(isnull(ri!text), null,
    if(len(ri!text)<5,ri!text, joinarray(
    char(
    insert(
    code(
    ri!text
    ),
    45, /* To Insert Hyphen */
    (
    (
    enumerate(
    quotient(
    len(
    ri!text
    ),
    local!insertIndex
    )
    ) + 1
    ) * local!insertIndex
    ) + 1
    )
    )
    )
    )
    )
    )
Children
No Data