Strings - HiStructClient/femcad-doc GitHub Wiki
Basic string definiton uses quotation marks
"this is a string"
String can be composed using + sign
A := "First name"
B := "Last name"
C := A + ", " + B
gives
C := "First name, Last name"
["Hi","my","friend"].JoinStrings()
"Himyfriend"
["Hi","my","friend"].JoinStringsWith(" ")
"Hi my friend"
strAr = ["Hi","my","friend"]
idxAr = [1,0,1,0,2]
idxAr.JoinStringsFn(i=>strAr[i])
"myHimyHifriend"
strAr = ["Hi","my","friend"]
idxAr = [1,0,1,0,2]
idxAr.JoinStringsWithFn("-",i=>strAr[i])
"my-Hi-my-Hi-friend"
array.ToString(digits wanted)
A := 35.6568465
B := A.ToString("0")
gives
B := "36"
Notes to digits count:
There is a systematic format that defines how many digits in front of/after the decimal point is displayed. One can either use:
- zeros to define it precisely,
- hashes and zeros to limit the numeber of digits (if exist),
- predefined formats in form of "F" or "E" + number
A := 123456.0987
B := A.ToString("0.0") => 123456.1
A := 123456.0987
B := A.ToString("000 000 0") => 012 345 6
A := 123456.11111
B := A.ToString("#.00#") => 123456.111
A := 123456.0987
B := A.ToString("F3") => 123456.099
A := 123456
B := A.ToString("E") => 1.234560E+005
It is possible to extract a substring from particular one.
string.Substring(number)
string.Substring(number, number)
name := "IPE 360"
type := name.Substring(0,3)
height := name.Substring(4)
gives
type := "IPE"
height := "360"
!! make sure the string is longer than used numbers !!
Test whether the string contains some sub-string
A := "Hello".Contains( "el" )
B := "Hello".Contains( "World" )
gives
A := True
B := False
It is possible to find the position of substring in string. It returns starting position of first appearance of the substring.
A := "Hello world!".IndexOf( "o" )
B := "Hello world!".IndexOf( "world" )
gives
A := 4
B := 6
It is possible to get the length of string.
length := someString.Length
A symbol in string can be replaced with:
replacedString := ("Zprav si to.").Replace("Z", "S") => "Sprav si to."
stringWithSpaces := ("0, 1, 2, 3 ").Replace(" ","") => "0,1,2,3"
Quotation marks can be created with:
quoteString = Fcs.Converters.ToJson( "" ).Substring( 1, 1 )
it is possible to use similar trick as for quotation marks, but it is necessary to make sure the string can be converted into value.
stringToNum := str => Fcs.Converters.ParseJson(" { 'myVal':"+str+"}").myVal
(this function is available in FcsFunctions (branch Apac_MT))
When you need to convert array of values to one string with values separated by commas, this function can be used:
ArrayToOneString := array => ( (array.Count > 0)
?( array.Aggregate( [], a, b => a + ( ", " + b ) ).Substring(4) )
:(Fcs.Exception.Throw( "Array must have at least one string." ) ) )
(the function is available in FcsFunctions (branch Deve-TB in fcs-HBC repos.)