Preceding Zeros on Numbers (With Letters on Some) - printf

an awful post title I know, struggled with that one!
Basically I have a list of numbers ranging from 1 - 230(ish)
I'm using sprintf( '%03d', $num) to output the numbers so that they have preceding zeros if necessary.
However something has buggered it all up, as I see some of the numbers also have letters in them (e.g. 134a, 134b etc).
So those numbers all currently output as '134'
I tried setting sprintf to %04d but that didn't work either, it just displayed them as '0134'
Does anyone have any suggestions?

Sounds like hexadecimal numbers. Use "%04x".

Related

regex decimal with negative

with the help of this thread I have tweak a regex for my use.
Decimal number regular expression, where digit after decimal is optional
So far I have this /^-?[1-9]$|^,\d+$|^0,\d$|^[1-9]\d*,\d*$
It works for
-12
0
1
It does not work for
-1,
-1,1
what I want is:
-1,1
may a kind soul explain what I am missing or doing wrong with this regex pls? Thank you very much!
I am tweaking it with : https://regexr.com/6sjkh but it's been 2 hours and I still don't know what I am missing. I don't know if language is important but I am in visual basic.
The thread you are quoting in your question has already some good answers. However if you do not need to also capture + and do not care about numbers without the leading zero before the comma and no thousand separator I would recommend the following:
/^-?\d+(,\d+)?/
The ^ indicates the beginning so that no other text in front is allowed
The -? is allowing a negative sign ( you need to escape this with \ as - can be a special character
\d+ expects 1 or more digits
The last part in parentheses covers the fractional part which as a whole can occure 0 or one time due to the question mark at the end
, is the decimal separator (if you want to have dots you need to put her ., as a dot is the special character for any character and also needs to be escaped if you look for a real dot)
\d+ is again one or more digits after the comma
I hope this helps a bit. Besides this I can also recommend using an online regular expression tool like https://regex101.com/

How to get the part of a string after the last occurrence of certain character?

I would like to have the substring after the last occurrence of a certin character.
Now I found here how to get the first, second or so parts, but I need only the last part.
The input data is a list of file directories:
c:\dir\subdir\subdir\file.txt
c:\dir\subdir\subdir\file2.dat
c:\dir\subdir\file3.png
c:\dir\subdir\subdir\subdir\file4.txt
Unfortunately this is the data I have to work it, otherwise I could list it using command prompt.
The problem is that the number of the directories are always changing.
My code based on the previous link is:
select (regexp_split_to_array(BTRIM(path),'\\'))[1] from myschema.mytable
So far I've tried some things in the brackets that came in to my mind. For example [end], [-1] etc.
Non of them are working. Is there a way to get the last part without rearranging my strings backwards, and getting the first part, then turning it back?
You can use regexp_matches():
select (regexp_matches(path, '[^\\]+$'))[1]
Here is a db<>fiddle.

Set standard number format with thousand separator, 2 decimals and minus sign for negative numbers using VBA?

I've seen the question asked before on stackoverflow, how to get normal number format with thousand separator and 2 decimals. The answer was to set:
rng.NumberFormat = "##0.00"
But this is incomplete, because, at least on my computer, I don't get any space separator between millions and thousands. So I have changed that to:
rng.NumberFormat = "### ### ##0.00"
But this is again incomplete, because for some reason negative numbers were formatted to look like they have a space between the minus sign and the number. See below:
- 12.4
So, there are some things left to do to arrive at Excels "built-in" "format as number" formats. Additionally the formatting that I apply though VBA is described as Custom by Excel.
Is there any way to set the format to be the standard built in format as number with thousand separators, 2 decimals and minus signs for negative numbers?
I'm looking for something like:
rng.NumberFormat = "Number, 2, minus"
rng.NumberFormat = "# ##0.00:-# ##0.00"
You put the format for positive numbers before : and the format for negative after. You don't need to put hundreds of # signs in the format, just enough to show what the 1000's separator is.

replace in word (wildcards) for multiple rows

I want to make a search/replace macro in word which is on 2 or 3 rows, like this
"art. 2
2
pct. 22 din"
and convert it to this
"art. 2<sup>2</sup>
pct. 22 din"
instead of art. i can have other words too like lit., pct., alin. and the numbers are always different
i tried to use the next wildcard replace but it doesn't work:
search: "(art. )([0-9]{1;})(^13)([0-9]{1;})(^13)"
replace: "\1\2<sup>\3</sup>^p"
if i type only (art. )([0-9]{1;})(^13) at the search field it works, but if i type the rest it doesn't find anything
Probably a bit late to be helpful, but I think this will do the trick, if I odd the horrible Word syntax correctly (I used this guide to check).
Search: ([a-z]#. )([0-9]#)^13([0-9]#)^13
With your replace as before.
First line match:
([a-z]#. ) - Any lower case letter occurring 1 or more times, followed by a dot.
([0-9]#) - Any digit occurring one or more times.
^13 - Paragraph mark.
Second line match:
([0-9]#) - Any digit occurring one or more times.
^13 - Paragraph mark.
If you find yourself doing stuff like this a lot, it might be worth using something that supports more common regular expressions (e.g. Notepad++ or similar). You might find the syntax a little bit more readable, and it would have the added bonus of teaching you something you can apply across many other environments.

unwanted leading blank space on oracle number format

I need to pad numbers with leading zeros (total 8 digits) for display. I'm using oracle.
select to_char(1011,'00000000') OPE_NO from dual;
select length(to_char(1011,'00000000')) OPE_NO from dual;
Instead of '00001011' I get ' 00001011'.
Why do I get an extra leading blank space? What is the correct number formatting string to accomplish this?
P.S. I realise I can just use trim(), but I want to understand number formatting better.
#Eddie: I already read the documentation. And yet I still don't understand how to get rid of the leading whitespace.
#David: So does that mean there's no way but to use trim()?
Use FM (Fill Mode), e.g.
select to_char(1011,'FM00000000') OPE_NO from dual;
From that same documentation mentioned by EddieAwad:
Negative return values automatically
contain a leading negative sign and
positive values automatically contain
a leading space unless the format
model contains the MI, S, or PR format
element.
EDIT: The right way is to use the FM modifier, as answered by Steve Bosman. Read the section about Format Model Modifiers for more info.