The mgiString Tag

Tag Behavior

The mgiString tag encodes or decodes a string of text or the contents of an entire file for URL or HTML characters.


Tag Syntax

The mgiString tag has one required parameter and three optional parameters. In addition, the mgiString tag has required and optional parameters for specific functions.The tag form is:

<mgiString function="Function" string="Text" 
targetFileLocation="File Path" quoteResult="Yes/No">
</mgiString>

The mgiString tag can also be written with a beginning and ending tag. That tag form is:

<mgiString function="Function" targetFileLocation="File Path" 
quoteResult="Yes/No">
Text
</mgiString>

Required Parameters:

  • function="Function" where "Function" is the action to be performed on the text string. Valid functions are "urlEncode", "urlDecode", "htmlEncode", "htmlDecode", "trim", "replaceAll", "split", "subString" and "noOperation".
    • The urlEncode function replaces all URL reserved characters with an encoded version of the character (e.g., spaces in the URL are replaced with %20 characters).
    • The urlDecode function replaces all encoded characters with URL reserved characters (e.g., %20 characters are replaced with spaces).
    • The htmlEncode function replaces all HTML reserved characters with an encoded version of the character (e.g., quotation marks are replaced with &quot; characters).
    • The htmlDecode function replaces all encoded characters with HTML reserved characters (e.g., &quot; characters are replaced with quotation marks).
    • The trim function removes all whitespace (including spaces, tabs and returns) from the beginning and end of a string.
    • The replaceAll function finds a string and replaces it with another string. (2 additional required parameters, stringToReplace and replacementString- see below for details).
    • The split function extracts values with a delimiter. (2 additional required parameters, delimiter and index - see below for details).
    • The subString function extracts and displays a string of characters specified by the numeric location of the first character in the string and the length of the string. (2 additional required parameters, beginningIndex and length - see below for details)
    • The getWordCount function returns the total number of words in a string.
    • The getCharacterCount function returns the total number of characters in a string including spaces and tabs. (1 additional optional parameter, character - see below for details)
    • The toLowercase function changes the string to all lowercase letters.
    • The toUppercase function changes the string to all capital letters.
    • The padLeft function adds characters to the left of the string. (2 additional required parameters, beginningIndex and length - see below for details)
    • The padRight function adds characters to the right of the string. (2 additional required parameters, beginningIndex and length - see below for details)
    • The noOperation function does not change the string. The noOperation function can be used in conjunction with the quoteResult parameter to only enter quote marks around the string.

Optional Parameters for all Functions:

  • string="Text" where "Text" is the text that will be encoded or decoded. The targetFileLocation parameter and the string parameter are mutually exclusive. If the "string" parameter is present and the mgiString tag is not embedded in another MGI tag, the closing mgiString tag is required.
  • quoteResult="Yes/No" where "Yes" indicates that quotation marks are inserted around the string and "No" indicates that quotation marks are not inserted around the string. The quoteResult parameter must be used with the noOperation function.
  • targetFileLocation="File Path" where "File Path" is the relative path to a file (at the same level of the file structure or below) where the string function will be performed. The string function is performed for the entire file and when the string function is complete, the changes are saved to the file. The targetFileLocation parameter and the string parameter are mutually exclusive.

ReplaceAll Function Required Parameters:

  • stringToReplace="String" where "String" is the text that will be found and replaced by the replacement string. To find the escape characters carriage returns, line feeds, and tabs, use the designations, CR, LF, and TAB respectively. To find carriage returns and line feeds, use CRLF. To find carriage returns only, use CR. To find line feeds only, use LF. To find tabs, use TAB.
  • replacementString="String" where "String" is the text that will replace any string found by the stringToReplace parameter. To replace the string with the escape characters carriage returns, line feeds, and tabs, use the designations, CR, LF, and TAB respectively. To replace the string with carriage returns and line feeds, use CRLF. To replace the string with carriage returns only, use CR. To replace the string with line feeds only, use LF. To replace the string with tabs, use TAB.

Split Function Required Parameters:

  • delimiter="Delimiter" where "Delimiter" is any string of characters that separates values in a list. To include escape characters such as carriage returns, line feeds, and tabs, use the designations CR, LF and TAB respectively. The CRLF delimiter indicates that values are separated by carriage returns and line feeds. The CR delimiter indicates that values are separated by carriage returns. The LF delimiter indicates that values are separated by line feeds. The TAB delimiter indicates that values are separated by tabs.
  • index="Integer" where "Integer" is the number of the value to extract. For example, in the following tab-delimited list, an index of "2" will extract the second value "Smith".
Bob Smith 919-225-6329 919-225-6330

SubString Function Required Parameters:

  • beginningIndex="Number" where "Number" is an integer that indicates the numeric location of the first character to extract and display. For example, to extract the numeric month from the string "19991025", the beginningIndex would be "5".
  • length="Number" where "Number" is an integer that indicates the length in characters of the string including the beginningIndex. For example, to extract the numeric month from the string "19991025", the beginningIndex would be "5" and the length would be "2".

GetCharacterCount Function Optional Parameters:

  • character="CharacterToCount" where "CharacterToCount" is the specific character that you wish to count (e.g., if character="a", then the number of A's in the string is displayed). If the character parameter is not included, then all characters are counted.

PadLeft and PadRight Function Optional Parameters:

  • character="CharacterToAdd" where "CharacterToAdd" is the specific character that you wish to add to the left or right of the string. The default character is a space.
  • length="Number" where "Number" is an integer that indicates the length in characters of the padding. For example, to add four exclamation points to a string, the length would be "4". The default length is "1".


Example Usage and Output

<mgiString function="htmlEncode">
<mgiFieldContent name="NewsStory">
</mgiString>

The mgiString tag in this example will HTML Encode a news story that is submitted via a form.


Suggested Usage

  • Path Arguments
  • Form Processing
  • Database Searches


[Return to the Referencing MGI Menu]


[User Guide Main Menu] [Understanding MGI Menu] [Using MGI Menu] [Referencing MGI Menu]