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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 String padding with specified character
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

AKazak

Russia
1205 Posts

Posted - 06/10/2022 :  03:32:23 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

Edited by - AKazak on 06/10/2022 03:32:38 AM

YimingChen

1664 Posts

Posted - 06/10/2022 :  08:55:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
What about using Python?


James
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 06/10/2022 :  11:25:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

What about using Python?

James



Dear James,

Cool!
Thank you.

---
Andrey

Edited by - AKazak on 06/10/2022 11:31:09 AM
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 06/10/2022 :  11:36:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
How do I pad with a character other than "0"?
Hod do I pad from right?

---
Andrey
Go to Top of Page

aplotnikov

Germany
169 Posts

Posted - 06/10/2022 :  12:25:16 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply


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!

Edited by - aplotnikov on 06/10/2022 12:34:18 PM
Go to Top of Page

YimingChen

1664 Posts

Posted - 06/10/2022 :  3:42:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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!

Go to Top of Page

YimingChen

1664 Posts

Posted - 06/10/2022 :  3:45:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 06/10/2022 :  5:51:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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

Go to Top of Page

aplotnikov

Germany
169 Posts

Posted - 06/10/2022 :  6:19:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Substitution notation may not work in the Set Column Formula.


Dear James,

the question was "why?".

Alexei
Go to Top of Page

aplotnikov

Germany
169 Posts

Posted - 06/10/2022 :  6:35:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 06/10/2022 :  7:50:41 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

minimax

357 Posts

Posted - 06/12/2022 :  11:24:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 06/16/2022 :  03:36:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Seems to be that fixing the software is required.

---
Andrey
Go to Top of Page

snowli

USA
1426 Posts

Posted - 06/23/2022 :  4:52:51 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

AKazak

Russia
1205 Posts

Posted - 06/24/2022 :  02:08:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 06/24/2022 :  05:52:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

aplotnikov

Germany
169 Posts

Posted - 06/27/2022 :  04:32:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

aplotnikov

Germany
169 Posts

Posted - 06/27/2022 :  04:57:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

minimax

357 Posts

Posted - 06/28/2022 :  03:53:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000