Replace all characters to ASCII in PostgreSQL - sql

I have an input string as follows: "ABC1134M001020000089".
I want to convert the string to integer format. One of the methods I thought of was by replacing A,B,C,M to its respective ASCII Values.
How can I achieve this in PostgreSQL?

Related

How to insert delimiter in a string with kotlin

I have a mac string:
mac=7A2918D5434F
And I need to convert to this:
mac=7A:29:18:D5:43:4F
How can I do that in kotlin?
If you are sure that your initial string is correct you can do something like:
"7A2918D5434F".chunked(2).joinToString(":")
chunked(2) splits the string in chunks of size 2 (can be used for any Iterable).
jointToString(":") takes a list, joins the elements to string using : as delimiter

How to convert string with German characters to Blob in Firebird?

I want to convert a string into a blob with the f_strblob(CSTRING) function of FreeAdhocUDF. At this point I do not find a way to get my special characters like ß or ä shown in the blob.
The result of f_strblob('Gemäß') is Gem..
I tried to change the character set to UTF8 of my variables, but that does not help.
Is there a masking option which I did not find?
You don't need that function, and the FreeAdhocUDF documentation also marks it as obsolete for that reason.
In a lot of situations, Firebird will automatically convert string literals to blobs (eg in statements where a string literal is assigned to a blob value), and otherwise you can explicitly cast using cast('your string' as blob sub_type text).

Parse string with `T` to timestamp PostgreSQL

I have this string 2019-02-14T17:49:20.987 which I want to parse into a timestamp. So I am playing with the to_timestamp function and it seems to work fine except... The problem is with this T letter there. How do I make PostgreSQL skip it?
What pattern should I use in to_timestamp?
Of course I can replace the T with a space and then parse it but I find this approach too clumsy.
Quote from the manual
If there are characters in the template string that are not template patterns, the corresponding characters in the input data string are simply skipped over (whether or not they are equal to the template string characters).
So just put any non-template character there (e.g. X):
select to_timestamp('2019-02-14T17:49:20.987', 'YYYY-MM-DDXHH24:MI:SS.MS')
Online example: https://rextester.com/OHYD18205
Alternatively, you can simply cast the value:
select '2019-02-14T17:49:20.987'::timestamp
The string with T is a valid input literal for timestamp or timestamptz:
select '2019-02-14T17:49:20.987'::timestamp;
timestamp
-------------------------
2019-02-14 17:49:20.987
(1 row)

SAS: Why does the input function convert from character to numeric, and the put function convert from numeric to character?

SAS documentation defines the input and put functions as:
Input function: Returns the value that is produced when SAS converts an expression using the specified informat
Put function: Returns a value using a specified format.
So the input function takes the variable and an informat as arguments, while the put functions takes the variable and a format as arguments, right?
If that is the case, why is the input function used to convert a variable from character to numeric, while the put function is used to convert a variable from numeric to character?
Are the input and put functions more tied to informats and formats, respectively, as opposed to character to numeric and numeric to character conversions, respectively?
Also, what is the difference between the input and put functions and the input and put statements?
The last question answers the first one. It is easiest to think of the PUT() function and INPUT() function in terms of how the PUT and INPUT statements work.
The PUT statement is for printing data into a text file report. You can print numeric or character variables but you are always writing character strings. The INPUT statement is for reading data from a text file. You can read into numeric or character variables but you are always reading from character strings.

Convert 4 Byte String Array of Hex to Decimal

I am trying to convert a string of 4 bytes in a string to an integer number in LabView, currently I am using the string subset to break apart my string and then storing it into a String Indicator on the front panel, however, I need to convert that string to an int so I can show the decimal value as well as convert it from inches to mm. Here is what I'm doing now:
I've tried converting to double using the convert string to double functions as well as I've tried splitting it up using the index array...can't quite seem to get an int out ever. Thanks!
Do as Ton Plomp said and use the Scan From String block. However, in yours, you don't want to separate with commas and with spaces. Just do:
%x%x%x%x
And that should do it for ya. Don't forget to pull the scan down so you have 4 outputs.
You can use Scan from string with the following format string:
%x
You can expand the scan from string to scan multiple items at once.