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
  • You can use regular expression plug-in. Giving the 2 examples here, please check which satisfies your requirement

    string= "The local variable to use when evaluating the given expression."
    1) regexinsertmatchmarkers("\S{4}", stripwith(string, " "), "", "-", false)
    Returns : "Thel-ocal-vari-able-tous-ewhe-neva-luat-ingt-hegi-vene-xpre-ssio-n."

    2) regexinsertmatchmarkers("\S \S{3}|\S{2} \S{2}|\S{3} \S|\S{4}", local!string, "", "-", false)
    Returns: "The l-ocal- vari-able- to us-e whe-n eva-luat-ing t-he gi-ven e-xpre-ssio-n."

    Thanks,
    Dipak Ingle
Reply
  • You can use regular expression plug-in. Giving the 2 examples here, please check which satisfies your requirement

    string= "The local variable to use when evaluating the given expression."
    1) regexinsertmatchmarkers("\S{4}", stripwith(string, " "), "", "-", false)
    Returns : "Thel-ocal-vari-able-tous-ewhe-neva-luat-ingt-hegi-vene-xpre-ssio-n."

    2) regexinsertmatchmarkers("\S \S{3}|\S{2} \S{2}|\S{3} \S|\S{4}", local!string, "", "-", false)
    Returns: "The l-ocal- vari-able- to us-e whe-n eva-luat-ing t-he gi-ven e-xpre-ssio-n."

    Thanks,
    Dipak Ingle
Children
No Data