How do I declare a 2 digit integer with leading zero openvms - openvms

How do I declare a 2 digit integer with leading zero openvms
Example:
$month = 01
$month = month + 1
$write sys$output month
I want month to now be 02.

You don't. A symbol can be either a string or an integer. A string can contain zeroes or other characters wherever you want them. An integer just contains a numeric value.
You can format an integer as a string with leading zeroes using the f$fao lexical function:
$ FormattedMonth = f$fao( "!2ZB", month )
Ref: f$fao.

Related

How to extract just numeric value with REGEXP_EXTRACT in BigQuery?

I am trying to extract just the numbers from a particular column in BigQuery.
The fields concerned have this format: value = "Livraison_21J|Relais_19J" or "RELAIS_15 DAY"
I am trying to extract the number of days for each value preceeded by the keyword "Relais".
The days range from 1 to 100.
I used this to do so:
SELECT CAST(REGEXP_EXTRACT(delivery, r"RELAIS_([0-9]+J)") as string) as relayDay
FROM TABLE
I want to be able to extract just the number of days regardless of the the string that comes after the numbers, be it "J" or "DAY".
Sample data :
RETRAIT_2H|LIVRAISON_5J|RELAIS_5J | 5J
LIVRAISON_21J|RELAIS_19J | 19J
LIVRAISON_21J|RELAIS_19J | 19J
RETRAIT_2H|LIVRAISON_3J|RELAIS_3J | 3J
You may use
REGEXP_EXTRACT(delivery, r"(?:.*\D)?(\d+)\s*(?:J|DAY)")
See the regex demo
Details
(?:.*\D)? - an optional non-capturing group that matches 0+ chars other than line break chsrs as many as possible and then a non-digit char (this pattern is required to advance the index to the location right before the last sequence of digits, not the last digit)
(\d+) - Group 1 (just what the REGEXP_EXTRACT returns): one or more digits
\s* - 0+ whitespaces
(?:J|DAY) - J or DAY substrings.

extract a pattern if a number is higher than a specific integer using sed or awk

I want to extract the lines that contain numbers which exceed a specific Integer for example if I have the following code
INTEGER ( 16 )
INTEGER ( 16 )
INTEGER ( 6 )
INTEGER ( 18 )
I want to keep only the lines that contain INTEGER (n <= 16), so I want to have as an output
INTEGER ( 16 )
INTEGER ( 16 )
INTEGER ( 6 )
If you can be sure that there are always spaces before and after the digits, then you could use this awk:
awk '$3 <= 16' file
This simply checks whether the third field is less than or equal to 16.
However, it might be safer to use something like this:
awk -F'[^0-9]+' '/INTEGER *\( *[0-9]+ *\)/ && $2 <= 16' file
This sets the field separator to any number of non-digit characters, so the first field is empty and the second field contains the digits you're interested in. If the line matches the pattern (which is flexible with respect to spacing) and the digits are less than or equal to 16, the line is printed.

How to format integer as string with 2 digits?

I would like to format an integer 9 to "09" and 25 to "25".
How can this be done?
You can use either of these options:
The "0" Custom Specifier
value.ToString("00")
String.Format("{0:00}", value)
The Decimal ("D") Standard Format Specifier
value.ToString("D2")
String.Format("{0:D2}", value)
For more information:
Custom Numeric Format Strings
Standard Numeric Format Strings
If its just leading zero's that you want, you can use this:
value.tostring.padleft("0",2)
value.ToString().PadLeft(2, '0'); // C#
If you have 2 digits, say 25 for example, you will get "25" back....if you have just one digit, say 9 for example, you will get "09"....It is worth noting that this gives you a string back, and not an integer, so you may need to cast this later on in your code.
String formate is the best way to do that. It's will only add leading zero for a single length. 9 to "09" and 25 to "25".
String.format("%02d", value)
Bonus:
If you want to add multiple leading zero 9 to "0009" and 1000 to "1000". That's means you want a string for 4 indexes so the condition will be %04d.
String.format("%04d", value)
I don't know the exact syntax. But in any language, it would look like this.
a = 9
aString =""
if a < 10 then
aString="0" + a
else
aString = "" + a
end if

in VB.net, if nth digit after decimal is Zero, then Round function will apply for 7 digit

let say n decimal = 0.996010569
I have applied below code (round on 6th digit) :
txtDiscountRate.Text = Math.Round(Val(txtDiscountRate.Text.Trim), 6)
But since here its 6th digit is 0 (Zero), so its value become 0.99601.
But i wish it would be 0.996011.
logic is: if 6th digit is 0 or < 5 then it do Round from 7th digit
then our calculation will be right.
Please provide Code in VB.net.
Jerry
in above code.
CInt(Str(1).Char(5)) is showing error this error -----> " 'Char' is not a member of 'String'".
Scenario is described below:
in txtDiscountRate.text have value "0.996010500406591" .
in my coding i did
txtDiscountRate.Text = Math.Round(Val(txtDiscountRate.Text.Trim), 6) . (means considering round till digit throught)
so it giving value 0.99601 which is because of 6th digit after decimal is 0,
but i want to put condition, in decimal value, if on 6th digit after decimal is ( 0 or 1 or 2 or 3 or 4 ) and 7th digit after decimal is available then it round till 7th position.
else it round till 6th position.
Use the FormatNumber() function.
Maybe not the best and prettiest solution, but you can give it a try...
Dim Dec As Decimal = 0.996010569
Dim str() As String = Split(CStr(Dec), ".")
If CInt(Str(1).Chars(5)) < 5 Then 'It's Char number 5 since it's a zero-based index. So the first number = Index 0.
txtDiscountRate.Text = Math.Round(Val(txtDiscountRate.Text.Trim), 7)
Else
txtDiscountRate.Text = Math.Round(Val(txtDiscountRate.Text.Trim), 6)
End If

count occurences of string in substring with condition

I need to count how often a number is present in a string. it should count EVERY occurence with a whitespace in front, except those followed by a =.
For example:
If i need to know how many "1" there are in this string: this is a 1 ramdnom string with 2 numbers 1 with 1=something it should return 2, as the third one is followed by an =
To find the occurrences I am using this: occurences = mystring.Split(" 1").Length - 1
But how to exclude those followed by a =?
Thanks
Something like,
Dim occurrences = Regex.Matches(yourString, "\W[0-9]([^=]|$)").Count
If you'd like to do replacements, use a Regex.Replace overload.
Breaking it down, this expression matches
\W // any whitespace character
[0-9] // any deciaml digit
( // either
[^=] // not =
| // or
$ // the end of the string
)