Text.ConvertStr Method

Version: Available or changed with runtime version 1.0.

Replaces all chars in source found in FromCharacters with the corresponding char in ToCharacters and returns the converted string. If the length of the FromCharacters parameter and the ToChars parameter are different, an exception is thrown. If the parameter FromCharacters or the parameter ToChars is empty, the source is returned unmodified. Each element in source is only converted ONCE a double-replacement cannot happen.


NewString :=   Text.ConvertStr(String: String, FromCharacters: String, ToCharacters: String)


This method can be invoked without specifying the data type name.


 Type: String
The string that you want to convert.

 Type: String
The characters that you want to replace. This function is case-sensitive.

 Type: String
The new characters with which you want to replace the FromCharacters. This function is case-sensitive.

Return Value

 Type: String
The input string with the converted characters.


The characters in the FromCharacters parameter are replaced by the characters in the ToCharacters parameter.

If the lengths of the FromCharacters and ToCharacters strings are not equal, then a run-time error occurs.

If either the FromCharacters or the ToCharacters strings are empty, then the source is returned unchanged.


    OriginalString: Text[30];
    FromChars: Text[30];
    ToChars: Text[30];
    NewString: Text[30];
    Text000: Label 'Do you want to leave without saving?';
    Text001: Label 'lws';
    Text002: Label 'LWS';
    Text003: Label 'The original sentence is \\: %1';
    Text004: Label 'The sentence is converted to:\\ %1';
    OriginalString := Text000;  
    FromChars := Text001;  
    ToChars := Text002;   
    NewString := ConvertStr(OriginalString, FromChars, ToChars);  
    Message(Text003, OriginalString);  
    Message(Text004, NewString);  

The first message window shows:

The original sentence is:

Do you want to leave without saving?

The second message window shows:

The sentence is converted to:

Do you Want to Leave Without Saving?

See Also

Text Data Type
Getting Started with AL
Developing Extensions