Skip to main content
Solved

Attribute to specific form

  • November 2, 2017
  • 2 replies
  • 9 views

Forum|alt.badge.img

Hi,

Was thinking what would be simpliest way to make this..

For example making 1-2000-K35 to 0012000K000035

So idea is to have bunch of values into this same form.. (000-0000-K000000, without "-")

Not sure how to explain it easier.

For now I can make it with splitter, bunch of testers and concatenator.. Would think there is easier way to make it. Maybe with some regular expressions?

Best answer by takashi

I would split the source string using a StringSearcher with these parameters.

  • Contains Regular Expression: ^(\d+)-(\d+)-(\D)(\d+)$
  • Subexpression Matches List Name: _sub

Then, you can format each number part (_sub{0}.part, _sub{1}.part, _sub{3}.part) with StringFormatters as @redgeographics suggested, and concatenate all the elements of _sub{}.part.

Alternatively, this string expression performs formatting and concatenating at once.

@Format(%03s,@Value(_sub{0}.part))@Format(%04s,@Value(_sub{1}.part))@Value(_sub{2}.part)@Format(%06s,@Value(_sub{3}.part))

See here to learn how to use the @Format function: String Functions

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

redgeographics
Celebrity
Forum|alt.badge.img+62

I think you're on the right track. StringFormatter may come in useful too to add leading 0's


takashi
Celebrity
  • Best Answer
  • November 2, 2017

I would split the source string using a StringSearcher with these parameters.

  • Contains Regular Expression: ^(\d+)-(\d+)-(\D)(\d+)$
  • Subexpression Matches List Name: _sub

Then, you can format each number part (_sub{0}.part, _sub{1}.part, _sub{3}.part) with StringFormatters as @redgeographics suggested, and concatenate all the elements of _sub{}.part.

Alternatively, this string expression performs formatting and concatenating at once.

@Format(%03s,@Value(_sub{0}.part))@Format(%04s,@Value(_sub{1}.part))@Value(_sub{2}.part)@Format(%06s,@Value(_sub{3}.part))

See here to learn how to use the @Format function: String Functions