-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_to_lowercase.cpp
58 lines (46 loc) · 1019 Bytes
/
convert_to_lowercase.cpp
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
/*
Link:- https://practice.geeksforgeeks.org/problems/java-convert-string-to-lowercase2313/1
The task is to convert characters of string to lowercase.
Input: S = "ABCddE"
Output: "abcdde"
Explanation: A, B, C and E are converted to
a, b, c and E thus all uppercase characters
of the string converted to lowercase letter.
*/
string toLower(string s)
{
// code here
string ans = "";
for (int i = 0; i < s.length(); i++)
{
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] = s[i] + 32;
ans = ans + s[i];
// ans=ans+ (char)tolower(s[i]);
}
return ans;
}
/*
//Using tolower() function
string toLower(string s) {
string ans="";
for(int i=0;i<s.length();i++)
{
ans=ans+ (char)tolower(s[i]);
}
return ans;
}
*/
/*
/***** bonus *****
//Convert to CamelCase
s[0]=s[0]-32;
for(int i=0;i<s.size();i++)
{
if(s[i]==' ')
{
s[i+1]=s[i+1]-32;
}
}
return s;
*/