The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 String padding with specified character

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
AKazak Posted - 06/10/2022 : 03:32:23 AM
OriginPro 2022b (64-bit) SR1 9.9.5.167
Windows 7 Pro SP1 x64

Greetings!

I use Dec2Bin to generate a binary string.
However the resulting string length is variable depending on the input decimal number.

What is the easiest way to do left padding the resulting string with "0" to make all the results strings to have a fixed length, say 8 or 16?

Thank you.

---
Andrey
18   L A T E S T    R E P L I E S    (Newest First)
minimax Posted - 06/28/2022 : 03:53:50 AM
Hi aplotnikov,

1. yes, single value works.
2. % is very old and complicate syntax in LT and is hard to expand to support vectorization;
3. only dataset supports indexing access, string arrays in LT does have limited functionality only.
aplotnikov Posted - 06/27/2022 : 04:57:42 AM
Hi minimax,

1. It fails if you try to use vector as argument. I meant, it works if used with single value as argument.
2. And the main "why" is: why not to implement vectorization for each operation in LT? It may be very useful providing a consistent and clear (at least for LT beginners) approach.

PS. Still I do not understand, why I can access values in numerical arrays by simple indexing and cannot do the same with string arrays, being forced to use GetAt() method instead.
aplotnikov Posted - 06/27/2022 : 04:32:45 AM
Hi CP,

there is no difference between Russia and Germany by decimal separator - the most European countries (except 5.5 ones :) ) use comma as standard symbol for this purpose.

Regards,

Alexei
cpyang Posted - 06/24/2022 : 05:52:29 AM
Hi Andrey,

This is related mostly to German users, so may not apply to you. It has to do with comma. Origin will auto convert comma to "." for German users when entering column formula, and this bug has to do with that auto conversion.

Basically if comma is a decimal separator in your computer, and you type "f(a,b)" in Fx cell, Origin will convert it into "f(a.b)", or "f(a;b)" depending on computer separator settings, and this bug fix has to do with situation where this auto-conversion took place when it should not.


CP
AKazak Posted - 06/24/2022 : 02:08:12 AM
quote:
Originally posted by snowli

Hello,

We just released Origin 2022b sr1 which includes this fix.
comma , will auto convert to ; when decimal separator is , in your Origin.

Please feel free to download the sr1 installer and choose repair to upgrade if u already have 2022b on your PC.

https://www.originlab.com/restricted/demo_download/DLRequest.aspx?rq=dl&d=1&s=E

Thanks, Snow



Dear Snow,

Can you share an example of the fix, please?

---
Andrey
snowli Posted - 06/23/2022 : 4:52:51 PM
Hello,

We just released Origin 2022b sr1 which includes this fix.
comma , will auto convert to ; when decimal separator is , in your Origin.

Please feel free to download the sr1 installer and choose repair to upgrade if u already have 2022b on your PC.

https://www.originlab.com/restricted/demo_download/DLRequest.aspx?rq=dl&d=1&s=E

Thanks, Snow
AKazak Posted - 06/16/2022 : 03:36:38 AM
Seems to be that fixing the software is required.

---
Andrey
minimax Posted - 06/12/2022 : 11:24:59 PM
Hi aplotnikov,

quote:

The substitution $(%(Dec2bin(A)$), #8) works in scripts only and fails if used as column formula. Why?


1. As far as we try, it fails in both LT script and column formula.
2. The argument in substitution will be parsed immediately when execute in the 1st time, and thus fails in the subsequent loop.
i.e. in your sample data, it is interpreted as 100 for every cell.
cpyang Posted - 06/10/2022 : 7:50:41 PM
I was thinking about beta 2023, but I think you are right, we should make SR1 to fix a few things including this one.

CP
aplotnikov Posted - 06/10/2022 : 6:35:29 PM
Dear cpyang,

seems it is the same bug.

I would appreciate if you provide the improved version. Is it a new service release of 2022b?

Alexei
aplotnikov Posted - 06/10/2022 : 6:19:32 PM
quote:
Substitution notation may not work in the Set Column Formula.


Dear James,

the question was "why?".

Alexei
cpyang Posted - 06/10/2022 : 5:51:26 PM
quote:
Originally posted by aplotnikov

PPS. Parsing of column formula is buggy - it interprets comma erroneously as delimiter in many cases and automatically replaces it with points!



This might be the same bug we noticed in https://my.originlab.com/forum/topic.asp?TOPIC_ID=47488

It was fixed with ORG-25334 for next version. Would you like to get beta version which will be releasing very soon?

CP

YimingChen Posted - 06/10/2022 : 3:45:20 PM
quote:
Originally posted by AKazak

How do I pad with a character other than "0"?
Hod do I pad from right?

---
Andrey



This is just one thought.



James
YimingChen Posted - 06/10/2022 : 3:42:12 PM
Substitution notation may not work in the Set Column Formula. Maybe just use LT function like: text(value(Dec2bin(A)), "#8")

James

quote:
Originally posted by aplotnikov



PS. The substitution $(%(Dec2bin(A)$), #8) works in scripts only and fails if used as column formula. Why?

PPS. Parsing of column formula is buggy - it interprets comma erroneously as delimiter in many cases and automatically replaces it with points!

aplotnikov Posted - 06/10/2022 : 12:25:16 PM


PS. The substitution $(%(Dec2bin(A)$), #8) works in scripts only and fails if used as column formula. Why?

PPS. Parsing of column formula is buggy - it interprets comma erroneously as delimiter in many cases and automatically replaces it with points!
AKazak Posted - 06/10/2022 : 11:36:44 AM
How do I pad with a character other than "0"?
Hod do I pad from right?

---
Andrey
AKazak Posted - 06/10/2022 : 11:25:43 AM
quote:
Originally posted by YimingChen

What about using Python?

James



Dear James,

Cool!
Thank you.

---
Andrey
YimingChen Posted - 06/10/2022 : 08:55:05 AM
What about using Python?


James

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000