ZBrushCentral

Question: is there function of alignmenting number of digits?

I have the value like [varset, myValue, 1].
I would like to convert it to “001”. (if my Value is 10, it will be 010.)
Is there way to do that in ZScript?

I search from Reference.

I notice [FileNameAdvance] has that avility, but not for converter.

hi, it’s just something called padding, but there is no easy way to do it with ZScript,

  1. so basically you just get the length of myValue.
  2. you define a variable for the number of digit to reach ( here it’s 3).
  3. then you iterate in a loop 3 times or more dependingof the padding size you are looking for.

hope it helps
Nicolas

1 Like

Thank you, I can see a milestones!

Could I ask one more question?
Can I do [StrMerge] right to left?

[varset,temValue,"tem"]
	[Loop, 5 , 
		[varset,temValue, ["StrMergeLEFT(If it exists)",temValue, n]
		,
		n
	]

[note, temValue]

I expect.

43210tem

If that is possible, I just read the string one by one from right, put them to the new var from right, and put “0” when the string is empty.
(read from right, put from right)

Or, do I need make the function “right to left merger”?

Or, I think a just nonsence method?:disappointed_relieved:

yes you can do somthing like that to first read the very end character an decrement the counter from there to read char after char.

[VarSet, myString, "abcdef"]
[VarSet, myNewString, ""]
[VarSet, counter, [StrLength, myString]]
[Loop, counter+1,
	[VarSet, char, [StrExtract, myString, counter, counter]]
	// merge the current character
	[VarSet, myNewString, [StrMerge, myNewString, char]]
	//decrement the counter
	[VarDec, counter]
,n]
[Note, myNewString] // display "fedcba"

Hope this helps,
Nicolas

1 Like

Wow!I’m deeply grateful for answering with the actual script.
It is really supremely helpful!:bowing_man:

I would try to make [routine, padding] based on this.

1 Like

I know it’s messy, but it works! (I hope, but I feel also it include error land mines.)

The memo for someone who need padding.
// [Routincall, input , output, padding number]

[RoutineDef, MyRtPadding //my routine padding
,
	[VarSet, myString, myInput]
	[VarSet, myReverseString, ""]
	[VarSet, myNewString, ""]

	[VarSet, counter, [StrLength, myString]-1]

	[Loop, mydigits,
		[VarSet, char, [StrExtract, myString, counter, counter]]
		[IF, counter<0, //[StrLength, char]
		//If
			[VarSet, myReverseString, [StrMerge, myReverseString, "0"]]
		, //Else
			// merge the current character
			[VarSet, myReverseString, [StrMerge, myReverseString, char]]
			//decrement the counter
		]
		[VarDec, counter]
	
	,n]
	
	//[note,[StrMerge,"myReverseString is: ", myReverseString]]  //debug

	[VarSet, counter, [StrLength, myReverseString]]

	[Loop, counter+1,
		[VarSet, char, [StrExtract, myReverseString, counter, counter]]
		// merge the current character
		[VarSet, myNewString, [StrMerge, myNewString, char]]
		//decrement the counter
		[VarDec, counter]
	,n]

	[VarSet, myOutput, myNewString]

, myInput, myOutput,mydigits
]

[VarSet, testImput, "1234"]
[VarSet, testOutput, ""]
	
[RoutineCall,MyRtPadding, testImput, testOutput,6] // [Routincall, input , output, padding number]
[note,testOutput]

1 Like