String Manipulations functions

Top 

Example code : Split, Trim, TrimLeft, TrimRigth

procedure TForm1.W3Button17Click(Sender: TObject);

var abc, str : string;

arrStr : array of string;

begin

abc := "Atletico-MG;Cruzeiro;Flamengo;Botafogo";

arrStr := abc.Split(";");

  WriteLn(arrStr[0]);

  WriteLn(arrStr[1]);

 

WriteLn('------------------');

abc := "    How are you doing today?;I'm fine, and you?   ";

WriteLn(abc.TrimLeft);

WriteLn( TrimLeft(abc) );

WriteLn('------------------');

WriteLn(abc.TrimRight);

WriteLn( TrimRight(abc) );

WriteLn('------------------');

WriteLn( Trim(abc) );

WriteLn(abc.Trim(16,23));

WriteLn('------------------');

abc := abc.Trim(8,23);

WriteLn(abc);   // are you doing today

end;

Atletico-MG

Cruzeiro

--------

How are you doing today?;I'm fine, and you?

How are you doing today?;I'm fine, and you?

--------

    How are you doing today?;I'm fine, and you?

    How are you doing today?;I'm fine, and you?

--------

How are you doing today?;I'm fine, and you?

doing today

---------

are you doing today 

 

mytoggle_plus1JS output

function W3Button17Click(Self, Sender$14) {

      var abc$3 = "";

      var str$2 = "";

      var arrStr$1 = [];

      abc$3 = "Atletico-MG;Cruzeiro;Flamengo;Botafogo";

      arrStr$1 = (abc$3).split(";");

      WriteLn($DIdxR(arrStr$1,0,""));

      WriteLn($DIdxR(arrStr$1,1,""));

      WriteLn("------------------");

      abc$3 = "    How are you doing today?;I'm fine, and you?   ";

      WriteLn(TrimLeft(abc$3));

      WriteLn(TrimLeft(abc$3));

      WriteLn("------------------");

      WriteLn(TrimRight(abc$3));

      WriteLn(TrimRight(abc$3));

      WriteLn("------------------");

      WriteLn(Trim$_String_(abc$3));

      WriteLn(Trim$_String_Integer_Integer_(abc$3,16,23));

      WriteLn("------------------");

      abc$3 = Trim$_String_Integer_Integer_(abc$3,8,23);

      WriteLn(abc$3);

   }

 

 

Example code : After, Before, DeleteLeft, DeleteRight, Dupe, DupeString, StringOfString, QuotedStr, QuotedString, RightStr, LeftStr,  ReverseString, Reverse, LeftStr, MidStr, RightStr

procedure TForm1.W3Button17Click(Sender: TObject);

var abc, str : string;

arrStr : array of string;

begin

abc := "Clube Atletico Mineiro";

// After: returns characters after a delimiter

WriteLn(abc.After(" "));  //

// Before: returns characters before a delimiter

 WriteLn(abc.Before(" "));  //

WriteLn('------------------');

 

// DeleteLeft: delete N characters to the left

 WriteLn(abc.DeleteLeft(3));  //

WriteLn('------------------');

 

// DeleteRight: delete N characters to the right

 WriteLn(abc.DeleteRight(2));  //

WriteLn('------------------');

 

// Dupe: duplicate the string N times

 WriteLn(abc.Dupe(3));  // Uncaught ReferenceError: DupeString is not defined

 WriteLn(DupeString(abc,2));  //  Uncaught ReferenceError: DupeString is not defined

 WriteLn(StringOfString(abc, 3));

WriteLn('------------------');

 

str := QuotedStr(abc, '#');

WriteLn(str);

str := str.QuotedString(str);

WriteLn(str);

WriteLn('------------------');

//Right: return N characters to the right

WriteLn(RightStr(abc, 2));

WriteLn('------------------');

 

//Left: return N characters to the left

WriteLn(LeftStr(abc, 2));

WriteLn('------------------');

 

// Reverse: returns a version of the string with the character reversed

WriteLn(ReverseString(abc));

WriteLn( abc.Reverse );

WriteLn('------------------');

 

abc := 'Delphi is the BEST';// then

WriteLn(LeftStr(abc, 5)); //  'Delph'

WriteLn(MidStr(abc, 67));// 'i is th'

WriteLn(RightStr(abc, 6));//  'e BEST'

 

end;

Atletico Mineiro

Clube

------------------

be Atletico Mineiro

------------------

Clube Atletico Minei

------------------

Clube Atletico MineiroClube Atletico MineiroClube Atletico Mineiro

Clube Atletico MineiroClube Atletico Mineiro

Clube Atletico MineiroClube Atletico MineiroClube Atletico Mineiro

------------------

#Clube Atletico Mineiro#

#Clube Atletico Mineiro##Clube Atletico Mineiro##Clube Atletico Mineiro##Clube Atletico Mineiro#

------------------

ro

------------------

Cl

------------------

orieniM ociteltA ebulC

orieniM ociteltA ebulC

------------------

Delph

i is th

e BEST 

 

 

mytoggle_plus1JS output

function W3Button17Click(Self, Sender$14) {

      var abc$3 = "";

      var str$2 = "";

      var arrStr$1 = [];

      abc$3 = "Clube Atletico Mineiro";

      WriteLn(StrAfter(abc$3," "));

      WriteLn(StrBefore(abc$3," "));

      WriteLn("------------------");

      WriteLn((abc$3).substring(3));

      WriteLn("------------------");

      WriteLn(StrDeleteRight(abc$3,2));

      WriteLn("------------------");

      WriteLn(DupeString(abc$3,3));

      WriteLn(DupeString(abc$3,2));

      WriteLn(StringOfString(abc$3,3));

      WriteLn("------------------");

      str$2 = QuotedStr(abc$3,"#");

      WriteLn(str$2);

      str$2 = QuotedStr(str$2,str$2);

      WriteLn(str$2);

      WriteLn("------------------");

      WriteLn(RightStr(abc$3,2));

      WriteLn("------------------");

      WriteLn((abc$3).substr(0,2));

      WriteLn("------------------");

      WriteLn(ReverseString(abc$3));

      WriteLn(ReverseString(abc$3));

      WriteLn("------------------");

      abc$3 = "Delphi is the BEST";

      WriteLn((abc$3).substr(0,5));

      WriteLn(abc$3.substr(5,7));

      WriteLn(RightStr(abc$3,6));

   }