Mixing Strings!

I want to mix two Strings into one String (s1 and s2), it should work like that: The first character comes from s1 and the second character from s2, the third one from s1 and the fourth one from s2 and so on. But if one string is shorter than the other one, the missing space shall be filled with " "!

Pls help me!

Answers

  • Cool, what have you tried so far?

  • In the reference there is a section String with nfc etc.; but confusingly the most commands are found when you click on String in the section data in the reference and scroll down on the String page.

    Anyway : you presumably should look a bit into charAt and length () of a String

    Chrisir

  • How is it going?

    you should for loop i over s1 and read the content with s1.charAt(i)

    fill a String result with the result

    here is the idea:

    String result = ""; 
    
    String s1 = "Hello";
    String s2 = "Caroo";
    
    size (110, 100); 
    
    for (int i=0; i<s1.length(); i++) { 
      result = result + s1.charAt(i);
    }//for
    
    println(result);
    
Sign In or Register to comment.