Please enable JavaScript to view this site.

Codolex

The string parts activity can be used to get different parts of the activity

 

StringParts

Activity properties

 

Possible parts to search for in strings

 

Before text

All the text before a substring in a string, excluding the substring.

 

Example:

String: "The quick brown fox jumps over the lazy dog".

Search for: "quick".

 

begin

var StringPartsResult: string;

var Needle := 'quick';

var TextPosition := StringValue.IndexOf(Needle);

 StringPartsResult := Copy(StringValue, 0, TextPosition);

end;

Result: "The ".

 

Beyond text

All the text after a sub-string in a string, excluding the sub-string.

 

Example:

String: "The quick brown fox jumps over the lazy dog".

Search for: "quick".

 

begin

var StringPartsResult: string;

var Needle := 'quick';

var TextPosition := StringValue.IndexOf(Needle);

 

 StringPartsResult := EmptyStr;

if TextPosition > -1 then

begin

  var LengthToCopy := StringValue.Length - Needle.Length - TextPosition;

   TextPosition := TextPosition + Needle.Length + 1;

   StringPartsResult := Copy(StringValue, TextPosition, LengthToCopy);

end;

end;

Result: " brown fox jumps over the lazy dog ".

 

Duplicates

Duplicates the input string by given amount.

 

Example:

String: "brown fox"

Duplicate amount: 3

 

begin

var StringPartsResult: string;

 StringPartsResult := DupeString(StringValue, 3);

end;

Result: "brown foxbrown foxbrown fox"

 

Left part

Returns a sub-string that contains a number of characters from the beginning of the string.

 

Example:

String: "The quick brown fox jumps over the lazy dog".

Left string amount: 7.

 

begin

var StringPartsResult: string;

 StringPartsResult := LeftStr(StringValue, 7);

end;

Result: "The qui".

 

Mid part

Returns a sub-string that contains a number of characters from a starting position in the string.

 

Example:

String: "The quick brown fox jumps over the lazy dog".

Mid string amount: 7.

Starting position: 10.

 

begin

var StringPartsResult: string;

 StringPartsResult := MidStr(StringValue, 10, 7);

end;

Result: " brown ".

 

Right part

Returns a sub-string that contains a number of characters from the end of the string.

 

Example:

String: "The quick brown fox jumps over the lazy dog".

Right string amount: 7.

 

begin

var StringPartsResult: string;

 StringPartsResult := RightStr(StringValue, 7);

end;

Result: "azy dog".

 

Padding -> Right part & Left part

Adds a character to the end and/or front of a string a given amount of times.

 

Example:

String: "The quick brown fox jumps over the lazy dog".

Right string amount: 3.

Character to add: "-".

Add to: "Both"

 

begin

var StringPartsResult: string;

var PaddingLengthtoAdd := StringValue.Length + 3;

 StringPartsResult := StringValue.PadLeft(PaddingLengthtoAdd, '-');

 PaddingLengthtoAdd := PaddingLengthtoAdd + 3;

 StringPartsResult := StringPartsResult.PadRight(PaddingLengthtoAdd, '-');

end;

Result: "---The quick brown fox jumps over the lazy dog---".

 

Skip end

Removes a sub-string from a string based on a starting position and a number of characters to remove.

 

Example:

String: "The quick brown fox jumps over the lazy dog".

Starting position: 10.

Characters to remove: 10.

 

begin

var StringPartsResult: string;

 StringPartsResult := StringValue.Remove(10, 10);

end;

Result: "The quick jumps over the lazy dog".

 

 

© by GDK Software