Pascal - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Pascal Strings

Pascal Strings

shape Description

Strings resemble sentences. Strings are shaped by a rundown of characters, which is truly a variety of characters. Strings are extremely valuable when conveying data from the program to the client of the program. They are less valuable while putting away data for the PC to utilize.

String Functions

shape Description

There existed essential functions of Pascal that should work with string operations. The following are the various string functions.

Pos

The Pos function will scan for the string SubString inside the string S. On the off chance that the sub-string is not discovered, then 0 will be returned by the function. In the event that then again the sub-string is discovered, then the file whole number estimation of the principal character of the primary string that matches the character of the sub-string and it will be returned. The following is an example. [c]program exObjects; Var S : String; Begin S := 'Hey there! How are you?'; Write('The word "How" is found at char index '); Writeln(Pos('How', S)); If Pos('Why', S) <= 0 Then Writeln('"Why" is not found.'); End. [/c] Output:The following is the result. [c]The word "How" is found at char index 12 "Why" is not found.[/c]

Copy

The copy function will duplicate a few characters from string S beginning from character record Index. The following is an example. [c]Var S : String; Begin S := 'Hey there! How are you?'; S := Copy(S, 5, 6); { 'there!' } Write(S); End. [/c] Output:The following is the result. [c]there![/c]

Delete

The delete function erases a predetermined number of characters from the string. The following is an example. [c]Var S : String; Begin S := 'Hey Max! How are you?'; Delete(S, 4, 4); { 'Hey! How are you?' } Write(S); End.[/c] Output:The following is the result. [c]Hey! How are you?[/c]

Insert

The insert function is used to insert the string. The following is an example. [c]Var S : String; Begin S := 'Hey! How are you?'; Insert(S, ' Max', 4); Write(S); { 'Hey Max! How are you?' } End.[/c] Output:The following is the result. [c]Hey Max! How are you?[/c]

UpCase

The UpCase function is used to change the given string into upper case. The following is an example. [c]Var S : String; i : Integer; Begin S := 'Hey! How are you?'; For i := 1 to length(S) do S[i] := UpCase(S[i]); Write(S); { 'HEY! HOW ARE YOU?' } End.[/c] Output:The result will be as follows. [c]HEY! HOW ARE YOU?[/c]

Concat

The concat function is used to combine the both given string, the following is an example. [c]Var S1, S2 : String; Begin S1 := 'Hey!'; S2 := ' How are you?'; Write(S1 + S2); { 'Hey! How are you?' } End.[/c] Output: Now the result will be as follows. [c]Hey! How are you?[/c]

Summary

shape Key Points

  • The Val function is used to convert the given string into numeric.
  • The Str function is used to convert decimal value to string,
  • The string will form with the set of characters.