0% found this document useful (0 votes)
4 views

Lec11A Strings

Uploaded by

sekardesi0433
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lec11A Strings

Uploaded by

sekardesi0433
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Strin

gs
String Data
Type
• The String data type is used to store any textual data.
• This includes words, letters, or anything else you
would send in a text message.
• In programming, the text is delimited with double
quotes.
• For example: "CSU, Sacramento", "computer", and
"Year 1947" are all strings.
String Functions Data Type Conversion

Note:
‘ToCode(c)’ converts a character c to its ASCII equivalent.

ToFixed(r,i) is most commonly used for truncating number of


decimal digits for displaying. It should be noted that the
truncated value is no longer a real number. It becomes a
string.
Len(
S)
• Length of a
string
Char(s
,Returns
i) a character from the string s at index i.
Characters are indexed starting at 0.
ToChar(n)
Convert a character code n
into a character.
ToCode(c)
Convert a character c into a
character code (ASCII value).

ASCII table to be understood


carefully.
https://www.asciitable.com/
ToFixed(r,
i)
Convert real number r to a string
with i digits after the decimal
point.

This function is useful for


truncating decimal digits and other
related operations
(It is very important to note that that the truncated
value is now considered as a string and is not a
number anymore).
Converting a string to an integer

ToInteger(dat
a)
Declare String month
Declare Integer monthNumber

Display "Enter a month number between 1 and


12"
Input month
monthNumber = stringToInteger(month)

* Now ‘MonthNumber’ is an integer and we can use it for


arithmetic operations like an integer.

9
ToInteger(data)

Similarly, ToReal (x) is used to convert a string


x into a real number.
10
Converting integer or real number to a

string

ToString(data)
Flowgorithm examples using
strings
Reversing a String
Counting Vowels in a string
Masking all digits (0-9) in a
string and displaying only
characters.

*Note how ASCII values are


used for identifying if a
character is a digit or not
https://www.ascii-code.com/codechart

Thank
You

You might also like