-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringFuncDEMO.cpp
More file actions
82 lines (59 loc) · 2.48 KB
/
Copy pathStringFuncDEMO.cpp
File metadata and controls
82 lines (59 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//************************************************************************
// Author: Rolando Carreon
// Date:
// Language: C++
// Assignment: String Function Demo
// Description:
//************************************************************************
#include<iostream>
using namespace std;
int main()
{
//declare local varibles //
// strings defined to be called //
string string1 = "Hello World!";
string string2 = "Welcome to C++ Programming";
// string to be defined later on and called //
string string3;
// varible to store the length of the string function //
// use long instead of int to call longer varible name or value //
long stringlength;
// custom string with my name //
string yourname = "Rolando Rey Carreon";
// custom varible to stroe custome string //
long stringlength2;
// find the charcter length of the charcter string using string.length() //
cout << "The length of string1 is " << string1.length() << endl;
cout << "The length of string2 is " << string2.length() << endl;
// custom length finder //
cout << "Your Name string is " << yourname.length()
<< " letters long! " << endl;
// check the character at a position //
// string2.at(12) starts counting from 0 //
cout << "The chatcter at position 12 of string2 is: "
<< string2.at(12) << endl;
// string2[12] without the .at() also starts counting from 0 (Same thing) //
// string[12] also starts counting from 0 //
cout << "The chatcter at position 12 of string2 is: "
<< string2[12] << endl;
// custom charcter check //
cout << "The character at position 3 (4) of Your Name is: "
<< yourname[3] << endl;
// change a charcter at a position //
// string2 charcter at position 6 is replaced with 'E' //
string2[6] = 'E';
cout << "The new string2: " << string2 << endl;
// custom charcter change //
yourname[3] = '3';
cout << "Your new name is: " << yourname << endl;
// combine 2 strings together //
string3 = "\n\t" + string1 + "\n\t" + string2;
cout << "Combined string: " << string3 << endl;
// store the length of a string //
stringlength = string3.length();
cout << "The length of string3 is: " << stringlength << endl;
// custom Your Name length //
stringlength2 = yourname.length();
cout << "The length of Your new name is: " << stringlength2 << endl;
return 0;
}