Oracle, adding leading zeros to string (not number) - string

I am using Oracle (work space is TOAD) and I need to make my strings that if they are shorted then 10 characters then add leading zeros to make them all 10 digit strings.
For example if I have a string like this:
'12H89' need to be '0000012H89'
or
'1234' to be '0000001234'
How can this be done? Whats the best way?
Thanks in advance .

You can use the LPAD function for that, passing in the string, the length you want it to be, and the character to pad it with. For 10 digits with leading zeroes this would be:
LPAD('12H89', 10, '0')
The return value is the padded string.
See: http://www.techonthenet.com/oracle/functions/lpad.php

Related

How to check if all values in the list are the same length? And if not how to add extra digits to equalise those values?

I'm doing a little coding in Python, and I came up to the issue that some of my values and not the same length.
Desired length is 15 characters
for example:
string = ['110000111100111', '100100110011011', '001101100110', '01011010001110', '111100111001', '1101100111011']
Some of these values are different, and I want to add zeros to equalise them to the same length. Specifically by adding some zeros to those values that are shorter.
Can someone give me a hand on this?
Many thanks!
I tried comparing them and finding shorter values in the list. I'm new to this.
Try this:
s = ['110000111100111', '100100110011011', '001101100110', '01011010001110', '1100111001', '1101100111011']
s = [x.zfill(15) for x in s]
zfill() will pad a string with zeros on the left, up to the desired string length.

How to convert integer to fixed length hex string in Go?

I want to convert an integer to a hex string with a fixed length of 64 characters, prepended with zeros for integer values that do not use up all 32 hex values. If I try the following it adds spaces in front of s rather than zeros.
i := 898757
s := fmt.Sprintf("%64x", i)
fmt.Println(s)
The correct format is "%064x":
fmt.Printf("%064x\n", 898757)
00000000000000000000000000000000000000000000000000000000000db6c5
Where the leading 0 is a "flag" for the formatting string. Per the fmt docs:
0: pad with leading zeros rather than spaces;
for numbers, this moves the padding after the sign
My personal preference is to use a period to separate the flags from the length field. This technically works because . is not meaningful with the integer verbs and is ignored. I find it a useful visual indicator. The format string becomes "%0.64x".

(Python3) string's (real) length/width

Let's say I want to "underline" a string with dots with Python3 :
Everything's fine with ASCII characters : I get the length with len(mystring) and I write as much dots as needed. Here is an example with a string whose length is 8 :
mystring
........
But with non-ASCII characters len(mystring) doesn't return the result I need; e.g. len("列島") is 2, but I need 4 dots to underline the string :
列島
....
How can I get the correct result ? Any help would be appreciated !
... unicodedata.east_asian_width() does the trick.
See by example this implementation.

AS3 - "\u2605" NOT the same as "\\u"+"2605"?

Trying to make a textfield where people write the unicode without the backslash. I want to add the backslash after they typed it. So the user types u2605 and the code converts it to "\u2605", i then convert this to a unicode character and insert it in textflow.
My code:
this works:
span.text = publicFunctions.htmlUnescape(he.encode("\u2605"))
this doesn't work:
span.text = publicFunctions.htmlUnescape(he.encode("\\u"+"2605"))
how to make a string that acts as a unicode string?
Tried all sorts of things, escape(unescape()), convert to number, "\u", "\u" ... nothing helps.
trace("\u2605" == "\u"+"2605") ... will return false. So will
trace("\u2605" == "\u"+"2605")
"\u2605" is a string with a single character, the character with the code point 2605, while "\\u" + "2605" is a string with 6 characters (the backslash, the u and the four digit number).
If you want to construct a unicode character from just the four digits, you should be able to use String.fromCharCode. The thing is just that the escape sequence uses a hexadecimal number, while the method obviously takes a decimal number. So if the user enters a hexadecimal string, you will have to convert that first:
trace(String.fromCharCode(parseInt('2605', 16)) == '\u2605'));
That's an interesting issue! I don't think you can concatenate a string literal and achieve what you're trying to do. The relevant character escaping happens when the string literal is originally formed, which means that you need the whole sequence together in the first place.
But you should be able to take the user-supplied number and dynamically generate a Unicode string with String.fromCharCode(...).
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html#fromCharCode()

Adding blank spaces into a string in C#

I have this code
String coNum = customerOrderLine.coNum.PadLeft(10 - customerOrderLine.coNum.Length);
I know that customerOrderLine.coNum = "123456" So I should end up with coNum being having 4 empty spaces at the front of it but I end up with it being "123456". How do I fix this? I tried PadRight in case that was the mistake and it also failed to work. I have to have the 4 empty spaces at the beginning to pass it into the API I am working on or it will fail.
PadLeft takes a total length as a parameter, so I think you want
String coNum = customerOrderLine.coNum.PadLeft(10);
This is because you have incorrectly specified the totalWidth parameter of the Pad* method.
From docs:
The number of characters in the resulting string, equal to the number
of original characters plus any additional padding characters.[...] If totalWidth is equal to the length of this instance, the method
returns a new string that is identical to this instance.
PadLeft does not specify a default character to pad with; your second argument should be the character to use for the pad, i.e.:
String coNum = customerOrderLine.coNum.PadLeft(10, ' ');
Edit: Also the first argument should be total desired length, not number of pad characters to add, per #Matthew's answer.

Resources