Converts a string into an integer or real number as specified by the type of variable mold.
t = str2num(str, mold)
Where:
str
: String to convert to numbermold
: Real or integer value to identify the type and kind of the output.
It is only used to set the type of the return value, so it can be any value.It returns an integer or real with the number contained in the string.
The following program converts a string to a real number
PROGRAM str2numExample
USE FU_Strings, ONLY: str2num
IMPLICIT NONE
REAL :: f
CHARACTER(LEN=:), ALLOCATABLE :: s
s = '293.75'
f = str2num(s, f)
WRITE(*,*) f
END PROGRAM str2numExample
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str |
String to convert to number. |
||
integer(kind=i8), | intent(in) | :: | mold |
Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value. |
The number of the input string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str |
String to convert to number. |
||
integer(kind=i16), | intent(in) | :: | mold |
Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value. |
The number of the input string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str |
String to convert to number. |
||
integer(kind=i32), | intent(in) | :: | mold |
Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value. |
The number of the input string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str |
String to convert to number. |
||
integer(kind=i64), | intent(in) | :: | mold |
Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value. |
The number of the input string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str |
String to convert to number. |
||
real(kind=sp), | intent(in) | :: | mold |
Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value. |
The number of the input string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str |
String to convert to number. |
||
real(kind=dp), | intent(in) | :: | mold |
Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value. |
The number of the input string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str |
String to convert to number. |
||
real(kind=qp), | intent(in) | :: | mold |
Real or integer value to identify the type and kind of the output. It is only used to set the type of the return value, so it can be any value. |
The number of the input string.