In this post, we will see Character String Types | PPL | Sebesta | Elementary Data Types in Programming Language | character string types, data types in ppl, data types ppl, elementary data types in programming language, ppl, sebesta, introduction
3. Character String types
A character string type is one in which the values consist of sequences of characters.
Strings and Their Operations
The most common string operations are assignment, concatenation, substring reference, comparison, and pattern matching.
Character string types could be supported directly in hardware; but in most cases, software is used to implement string storage, retrieval, and manipulation.
i. C and C++
C and C++ use char arrays to store character strings.
In Java, strings are supported by the String class, whose values are constant strings, and the StringBuffer class, whose values are changeable and are more like arrays of single characters.
String s1=new String("Parag");
StringBuffer s2=new StringBuffer("Parag");
iii. C# and Ruby
C# and Ruby include string classes that are similar
to those of Java.
Python includes strings as a primitive type i.e. str.
For character and substring references, they act very much like arrays of characters.
However, Python strings are immutable, similar to the String class objects of Java.
In F#, strings are a class.
In ML, string is a primitive immutable type.
Pattern-matching capabilities using regular expressions are included in the class libraries of C++, Java, Python, C#, and F#.
String Length Options
The length can be static and set when the string is created. Such a string is called a static length string. e.g. Java, Python.
Limited dynamic length strings are those strings which are allowed to have varying length up to a
declared and fixed maximum set by the variable’s definition. e.g. C, C++.
Ada 95+ supports all three string length options.
Descriptor for Static Length Strings
Descriptor for Limited Dynamic Length Strings
Dynamic length strings require a simpler run-time descriptor because only the current length needs to be stored.
Watch following video:
Watch on YouTube: https://www.youtube.com/watch?v=q-jAz8AMOFo