String Functions

String Functions

This page discusses:

BuildDate

BuildDate

Signature

BuildDate() : Date

ReturnType

Date

BuildDeferredMessageNLS

Function used to build a NLS message (a message in a given language) by finding it in a CATXXX.CATNls file depending on the NLS client on a target machine. Its role is to store the information to build a message (could be error, warning or info) from catalog, key and inputs arguments. See also BuildDeferredMessageNLS on the server side.

Signature

BuildDeferredMessageNLS(MessageCatalog : String, MessageKey : String
 [, argument : Literal, ..]) : NLSMessage

Arguments

NameInput / OutputRequired?TypeComment
MessageCatalogInYesStringCATNls file name or .properties file name. File name without extension.
MessageKeyInYesStringKey name in the .CATNls or in the .properties file.
argumentInOptionalLiteralVariable arguments number.

The output is a structure composed of Catalog, Key and List of arguments, that will be affected to Parameters.

Note: The BuildMessageNLS on the client is replaced by a BuildDeferredMessageNLS on the server. .CATNls files are to be used on the client. The format must be as follows:
// Name of the catalog: Catalog1.CATNls
Message1.Request    = "";
Message1.Diagnostic = "No description for (/p1)";
Message1.Advice     = "You should add a description for (/p1)";
.properties files are to be used on the server. The format must be as follows:
# Name of the catalog: Catalog1.properties
Message1 = "No description for ({0})";

ReturnType

NLSMessage

Example

Parameters.NLSMessage = BuildDeferredMessageNLS("Catalog1", "Message1", "MyObject")

BuildMessageNLS

Enables you to send messages or ask questions through the Message and Question functions in the language of your choice. The BuildMessageNLS function can build a NLS message (a message in a given language) by finding it in a CATXXX.CATNls file.

Signature

BuildMessageNLS(MessageCatalog : String, MessageKey : String
 [, argument : Literal, ..]) : String

Arguments

NameInput / OutputRequired?TypeComment
MessageCatalogInYesString
MessageKeyInYesString
argumentInNoLiteral

ReturnType

String

Example

The KwrCATCatalog.CATNls file contains the following text:

Zero = "Zero";
One = "One /P1";
Two = "Two /P1 /P2";

Zero, One and Two are the messages. The first message has no arguments, the second has 1 argument, the third, 2 arguments. To display those messages in a Engineering Rules Capture rule for example, enter the following rule body:

  • Message (BuildMessageNLS("KwrCATCatalog","Zero"))
  • Message (BuildMessageNLS("KwrCATCatalog","One",x)) Where x is a parameter.
  • Message (BuildMessageNLS("KwrCATCatalog","Two",y,z)) Where y, and z are parameters.
Important:
  • If the function does not find the key or the .NLS catalog, it will return an empty string.
  • If there are too many parameters compared to the number of arguments of the message, the parameters will be ignored.
  • If there are too few parameters compared to the number of arguments of the message, the parameters will be replaced with a "???" string.
  • Note that the .NLS file is to be stored in the runtime view (in the msgcatalog directory)

DateFormat

Enables you to retrieve a date as a string.

Signature

DateFormat(format : String [, date : Date]) :
 String

%a     Abbreviated weekday name
%A     Full weekday name
%b     Abbreviated month name
%B     Full month name
%c     Date and time representation appropriate for locale
%d     Day of month as decimal number (01 -31)
%H     Hour in 24-hour format (00 - 23)
%I     Hour in 12-hour format (01 - 12) 
%j     Day of year as decimal number (001 - 366)
%m     Month as decimal number (01 - 12)
%M     Minute as decimal number (00 - 59)
%p     Current locale's A.M/P.M indicator for 12-hour clock
%S     Second as decimal number (00-59)
%U     Week or year as decimal number, with Sunday as first day of the week (00-53)
%w     weekday as decimal number (0-6; Sunday is 0)
%W     Week of year as decimal number, without Monday as first day of the week (00-53)
%x     Date representation for current locale
%X     Time representation for cullrent locale
%y     Year without century, as decimal number (00-99)
%Y     Year with century, as decimal number
%z, %Z Either the time zone name or the time zone abbreviation, depending on the registry settings; no characters
       if the time zone is unknown.
%%     Percent sign

Arguments

NameInput / OutputRequired?TypeComment
formatInYesString
dateInNoDate

ReturnType

String

FormatNumber

Formats a digit according to a format defined by the user (for example decimal or scientific).

Signature

FormatNumber([Real : Real, Format : String, Accuracy : Integer]) : String

Arguments

NameInput/OutputRequired?TypeComment
RealInRealThe digit you want to format.
FormatInStringNumber format. Can be one of the following:
  • decimal
  • hexadecimal
  • integer
  • octal
  • scientific
AccuracyInIntegerNumber of digits after the coma. The default value is 0.

ReturnType

String

Example

Let R (Real)
Let S (String)
R = 9.589
S = FormatNumber(R, “scientific”, 2) // now S contains “9.59e+000”
S = FormatNumber(R, “scientific”) // now S contains “1e+001”
S = FormatNumber(R, “decimal”, 5) // now S contains “9.58900”
S = FormatNumber(R, “integer”) // now S contains “10”

GetEnvVariableValue

Enables you to read the content of an environment variable.

Signature

GetEnvVariableValue(VarName : String) : String

Arguments

NameInput / OutputRequired?TypeComment
VarNameInYesStringName of the variable. It returns the name of the variable.

ReturnType

String

GetPLMOwner

Enables you to retrieve the PLM Owner of any kind of object.

  • If the object is inside a representation, it retrieves the representation that contains it.
  • If the object is a PLMEntity, it returns itself.
  • If the object is not persistent, it will return a NULL value.
  • The result of the GetOwner can be put in any kind of variable. But if you do not use a variable of the right type, it will be equal to NULL.
There are several ways to use GetPLMOwner but the main goal is to propagate a value from an object in a representation, into an attribute of the representation.
Note: Note that no particular license is required in case you run this function.
Signature
GetPLMOwner(Object : ObjectType) : UndefinedType

Arguments

NameInput / OutputRequired?TypeComment
ObjectInYesObjectType

ReturnType

UndefinedType

Example

let x(VPMRepReference)
x = GetPLMOwner (Point) /* Point is the point in the model */
x.V_Description = "Hello"

Repeat

Repeats a string as many times as defined by the user.

Signature

Repeat(String : String, Occurrence : Integer) : String

Arguments

NameInput/OutputRequired?TypeComment
StringInStringString you want to repeat.
OccurrenceInIntegerNumber of times the string should be repeated.

ReturnType

String

Example

Let Si, So (String)
Si = “hello”
So = Repeat(Si, 3) // now So contains “hellohellohello”

ReplaceAll

Lets you replace occurrences of a string by another one in a given string.

Signature

ReplaceAll(v1 : String, v2 : String, v2 : String) : String

Arguments

NameInput / OutputRequired?TypeComment
v1InYesString-
v2InYesString-
v2InYesString-

ReturnType

String

Example

  1. Create a knowledge action.
  2. Enter the following script:
    Let stringToModify(String)
    Let stringModified(String)
    Let replacingString(String)
    Let replacedString(Strnig)
    
    stringToModify = "test1234testest1234test" 		
    replacedString = "test"
    replacingString = "thisStringHasBeenModified"
    stringModified = ReplaceAll(stringToModify,replacedString,replacingString)
    Message(stringModified)	
    
  3. Execute the action and check that it displays: "thisStringHasBeenModified1234thisStringHasBeenModifiedest1234thisStringHasBeenModified".

ReplaceSubText

Enables you to replace the first occurrence of string with another string and returns the result.

Signature

ReplaceSubText(v1 : String, v2 : String, 
v2 : String) : String

Arguments

NameInput / OutputRequired?TypeComment
v1InYesString
v2InYesStringCan be specified either with their parameters names or with the string itself between quotes.
v2InYesStringCan be specified either with their parameters names or with the string itself between quotes.

ReturnType

String

SplitString

SplitString

Signature

SplitString(o : String, SeparatorChars : String, KeepEmptyString : Boolean) : List

Arguments

NameInput/OutputRequired?TypeComment
oInString

String to split.

SeparatorChars InString

Separation characters.

KeepEmptyString In Boolean

Keep empty string.

ReturnType

List

Example

 let strToSplit(String)
let str2(String)
let strF(String)

strToSplit = “abc1de23fgh4ij”
str2 = “1234”

let listResSplitFalse(List)
let listResSplitTrue(List)

set listResSplitFalse = SplitString(strToSplit, str2)   // argument 3: false is default value
set listResSplitTrue = SplitString(strToSplit, str2, true)

for strF inside listResSplitFalse
{
          Message(strF)
}
// previous loop displays successively the values:  “abc”, “de”, fgh”, “ij”


for strF inside listResSplitTrue
{
          Message(strF)
}
// previous loop displays successively the values:  “abc”, “de”, “”, fgh”, “ij”

ToLower

Enables you to change all upper-case letters of a string to lower-case.

Signature

ToLower(v1 : String) : String

Arguments

NameInput / OutputRequired?TypeComment
v1InYesStringName of the string type parameter.

ReturnType

String

ToString

Enables you to convert an integer into a string.

Signature

ToString(Real) : String

Arguments

NameInput / OutputRequired?TypeComment
InYesReal

ReturnType

String

Example

let s = ""
s = ToString(3.4)
let s = ""
s = ToString(3.4)

ToUpper

Enables you to change all lower-case letters of a string to upper-case.

Signature

ToUpper(v1 : String) : String

Arguments

NameInput / OutputRequired?TypeComment
v1InYesStringName of the string type.

ReturnType

String

String.Search()

Searches for the first occurrence of a sub string in a String type parameter. It returns the index (o or 1) of the start of the substring. It returns -1 if the substring specified is not found.

Signature

String.Search(a1: String [, String, index: Integer, Forward: Boolean]) : Integer

Arguments

NameInput / OutputRequired?TypeComment
a1InYesStringName of the SubString parameter
InNoString
indexInNoIntegerCorresponds to the index of the character to start the search. The index starts at 0. If you're not using this argument, the default value is 0.
ForwardInNoBooleanIndicates if we want to search the string from the beginning of the string (forward equal to true) or from the end (forward equal to false). Note that when we are searching backward, the index value corresponds to the rank of the character in backward order. If you're not using this argument, it will search in forward mode.

ReturnType

Integer

Example



String.Extract()

Returns the sub string starting at a given position with a specified length.

Signature

String.Extract(a1: String, Integer, Integer) : String

Arguments

NameInput / OutputRequired?TypeComment
a1InYesString
InYesInteger
InYesInteger

ReturnType

String

Example

let Responsible = "Cilas Evans Evans"
Message ("#",Responsible.Extract(2,2))
/* "la" appears. */

String.Length()

Converts length on String type.

Signature

String.Length() : Integer

ReturnType

Integer

Example

            

String.ToReal()

Converts a string into a real.

Signature

String.ToReal(a1: String) : Real

Arguments

NameInput / OutputRequired?TypeComment
a1InYesString

ReturnType

Real

Example

let s = "2.3"
let r=0.0
r = s -> ToReal()

Repeat

Function used to repeat a given string.

Signature

Repeat(String : String, Occurrence : Integer) : String

Arguments

NameInput/OutputRequired?TypeComment
StringInYesStringString to repeat
OccurrenceInYesIntegerNumber or times the string is repeated

ReturnType

String

FormatNumber

Function used to format a number according to a defined format (for example decimal, scientific).

Signature

FormatNumber([Real : Real, Format : String, Accuracy : Integer]) : String

Arguments

NameInput/OutputRequired?TypeComment
RealInNoRealNumber to format
FormatInNoStringNumber format.
AccuracyInNoIntegerNumber of decimal places

ReturnType

String