4D v14.3

Substring

Home

 
4D v14.3
Substring

Substring 


 

Substring ( source ; firstChar {; numChars} ) -> Function result 
Parameter Type   Description
source  String in String from which to get substring
firstChar  Longint in Position of first character
numChars  Longint in Number of characters to get
Function result  String in Substring of source

The Substring command returns the portion of source defined by firstChar and numChars.

The firstChar parameter points to the first character in the string to return, and numChars specifies how many characters to return.

If firstChar plus numChars is greater than the number of characters in the string, or if numChars is not specified, Substring returns the last character(s) in the string, starting with the character specified by firstChar. If firstChar is greater than the number of characters in the string, Substring returns an empty string ("").

Warning: When you use this command in a multi-style context, you need to convert any Window end-of-line characters ('\r\n') into single ('\r') characters in order for processing to be valid. This is due to the mechanism which normalizes 4D line endings to ensure multi-platform compatibility for texts. For more information, refer to .

This example illustrates the use of Substring. The results, described in the comments, are assigned to the variable vsResult.

 vsResult:=Substring("08/04/62";4;2) ` vsResult gets "04"
 vsResult:=Substring("Emergency";1;6) ` vsResult gets "Emerge"
 vsResult:=Substring(var;2) ` vsResult gets all characters except ` the first

The following project method appends the paragraphs found in the text (passed as first parameter) to a string or text array (the pointer of which is passed as second parameter):

  ` EXTRACT PARAGRAPHS
  ` EXTRACT PARAGRAPHS ( text ; Pointer )
  ` EXTRACT PARAGRAPHS ( Text to parse ; -> Array of ¶s )
 
 C_TEXT($1)
 C_POINTER($2)
 
 $vlElem:=Size of array($2->)
 Repeat
    $vlElem:=$vlElem+1
    INSERT IN ARRAY($2->;$vlElem)
    $vlPos:=Position(Char(Carriage return);$1)
    If($vlPos>0)
       $2->{$vlElem}:=Substring($1;1;$vlPos-1)
       $1:=Substring($1;$vlPos+1)
    Else
       $2->{$vlElem}:=$1
    End if
 Until($1="")

 
PROPERTIES 

Product: 4D
Theme: String
Number: 12

 
HISTORY 

Created: < 4D v6

 
SEE ALSO 

Position

 
ARTICLE USAGE

4D Language Reference ( 4D v11 SQL Release 6)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)

Parent of : Substring ( 4D v13.5)