CSE 8B Chapter Notes - Chapter 10.10, 11.11: String Literal, Regular Expression, Delimiter

25 views3 pages

Document Summary

It cannot be changed once it is created. Changing a string means having to create another string object. Syntax for creating a string from a string literal: string newstring = new string(stringliteral, stringliteral can be replaced with an array of char. You can also do this: tri(cid:374)g (cid:373)essage = (cid:862)hello (cid:449)orld! (cid:863) Strings are immutable contents cannot be changed: tri(cid:374)g s = (cid:862)ja(cid:448)a(cid:863), s = (cid:862)hello(cid:863); In the code above: s poi(cid:374)ts to a tri(cid:374)g o(cid:271)je(cid:272)t (cid:449)ith (cid:272)o(cid:374)te(cid:374)t (cid:862)ja(cid:448)a(cid:863) After the se(cid:272)o(cid:374)d state(cid:373)e(cid:374)t, a (cid:374)e(cid:449) tri(cid:374)g o(cid:271)je(cid:272)t (cid:449)ith (cid:272)o(cid:374)te(cid:374)t (cid:862)hello(cid:863) is created, and s now points to that object. In the code above, s1 and s3 refer to the same object; a new object is created for s2. Some methods can replace a string: however, these methods do not change the contents of the original string, they return a new, altered string.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions