# Function to turn sentence into all caps

**URL:** <https://discourse.processing.org/t/function-to-turn-sentence-into-all-caps/4673>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 20, 2018, 5:52am UTC](https://discourse.processing.org/t/function-to-turn-sentence-into-all-caps/4673 "2018-10-20T05:52:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![engg23369](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@engg23369](https://discourse.processing.org/u/engg23369)\
**Post date:** [October 20, 2018, 5:52am UTC](https://discourse.processing.org/t/function-to-turn-sentence-into-all-caps/4673/1 "2018-10-20T05:52:11Z")

</div>

I’m trying to make my own function that takes a sentence and turns every letter in it into an uppercase. I know there’s a pre-defined function that does this but i’m trying to make own myself. Here’s what I have so far. If I just knew how to take every value of ‘p’ and line them in order as a string id be golden. Thanks

```auto
int p;
char x ;
void setup () 
{
 String str = "I am Happy to See You.";
 String capstr = All_uppercase (str);
 println(capstr);
}

String All_uppercase(String a)
{
  char x;
  for(int i = 0 ; i < a.length(); i ++)
  {
    int p ;
    if(a.charAt(i) > 96)
    {
       p = a.charAt(i) - 32; 
    }
    else
    {
       p = a.charAt(i);
    }
    x = (char(p));
  }

  String word = 
 
 return word;
    
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [October 20, 2018, 6:04am UTC](https://discourse.processing.org/t/function-to-turn-sentence-into-all-caps/4673/2 "2018-10-20T06:04:46Z")

</div>

You can concatenate them onto an empty string. Example:

```auto
String alphabet = "";

for( int i = 0; i < 26; i++ ){
  alphabet = alphabet + char('A' + i );
}

println( alphabet );

```

---

<div class="post-metadata">

**Author:** ![engg23369](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@engg23369](https://discourse.processing.org/u/engg23369)\
**Post date:** [October 20, 2018, 6:58pm UTC](https://discourse.processing.org/t/function-to-turn-sentence-into-all-caps/4673/3 "2018-10-20T18:58:32Z")

</div>

Sorry I don’t quite understand

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [October 20, 2018, 7:55pm UTC](https://discourse.processing.org/t/function-to-turn-sentence-into-all-caps/4673/4 "2018-10-20T19:55:42Z")

</div>

The process is this:

```java
// Start the ALL_UPPERCASE function, taking in an input string.
  // Have a character, x, that will store the result of converting a single letter to uppercase
  // Have a String, output, that will contain all the letters the loop has processed so far.
  // Initially, this output string is the empty string, "".
  // Loop over every letter in the input string. For each letter,
    // If the letter is a lowercase letter,
      // make character x be the uppercase version of it.
    // otherwise,
      // Make x be that letter.
    // End of conditional statement. the variable x is the next character to add at this point.
    // Next, append the character x to the output string.
    // Maybe print the output string here so you can see the progress.
  // End of looping over every character in the input string.
  // Return the output string.
// End of function

```

Do you understand the process? Can you now write the line of code for each step?

---

<div class="post-metadata">

**Author:** ![engg23369](https://avatars.discourse-cdn.com/v4/letter/e/e495f1/32.png) [@engg23369](https://discourse.processing.org/u/engg23369)\
**Post date:** [October 20, 2018, 8:08pm UTC](https://discourse.processing.org/t/function-to-turn-sentence-into-all-caps/4673/5 "2018-10-20T20:08:31Z")

</div>

Took me a bit of extra thinking, your help was just enough to let me figure it out. Thank you so much. Here’s the code:

```auto
int p;
char x ;
void setup () 
{
 String str = "it works, im so happy.";
 String capstr = All_uppercase (str);
 println(capstr);
}

String All_uppercase(String a)
{
 int x ;
 char c;
 String output = "";
  for(int i = 0 ; i < a.length(); i ++)
  {
    
    if(a.charAt(i) > 96)
    {
       x = a.charAt(i) - char(32); 
    }
    else
    {
       x = a.charAt(i);
    }
     c = char(x);
    output = output + c;
  }

  return output;
  
}

```

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [October 20, 2018, 9:50pm UTC](https://discourse.processing.org/t/function-to-turn-sentence-into-all-caps/4673/6 "2018-10-20T21:50:53Z")

</div>

@engg23369 Great! the program works well 🙂 Hope everything was cleared up for you.
