# Text, go to the next line after finding a certain character

**URL:** https://discourse.processing.org/t/text-go-to-the-next-line-after-finding-a-certain-character/7057
**Category:** Coding Questions
**Created:** [December 31, 2018, 2:13pm UTC](https://discourse.processing.org/t/text-go-to-the-next-line-after-finding-a-certain-character/7057 "2018-12-31T14:13:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)
#### Post date: [December 31, 2018, 2:13pm UTC](https://discourse.processing.org/t/text-go-to-the-next-line-after-finding-a-certain-character/7057/1 "2018-12-31T14:13:01Z")

</div>

Hi guys,  
I’m going crazy on something really stupid, but I just can not solve it.  
I would like to wrap after I’ve found a specific character.  
the code I am using is this:

```auto
String[] lines; 
String randText;

void setup() {
  size(1280, 720);
  lines = loadStrings("howl.txt");
  background(0);
  frameRate(1);
}

void draw() {
  //fill(0, 255);
  //rect(0, 0, width, height);
  //background(0);

  randText=lines[frameCount].toUpperCase();

  for (int k=0; k<randText.length(); k++) {
    if (str(randText.charAt(k)).equals(" ")==true) {
      //randText.charAt(k)=; here i want to go to the next line
    }
  }
  text(randText, 10, frameCount*12);
}

```

thank you in advance!!

---

<div class="post-metadata">

### Author: ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)
#### Post date: [December 31, 2018, 2:49pm UTC](https://discourse.processing.org/t/text-go-to-the-next-line-after-finding-a-certain-character/7057/2 "2018-12-31T14:49:52Z")

</div>

ok…i’ve found this method StringBuffer, but now i want decide if a specific character have be to changed or not.  
is there a way to do it?

```auto
String[] lines; 
String randText;
StringBuffer sb;

void setup() {
  size(1280, 720);
  lines = loadStrings("howl.txt");
  //ArrayList<StringBuffer> sb = new ArrayList<StringBuffer>();
  sb = new StringBuffer(lines.length);
  for (int i=0; i<lines.length; i++) {
    sb.append(lines[i]);
  }
  background(0);
  frameRate(1);
  noLoop();
}

void draw() {
  randText=sb.toString();
  randText=randText.replace(' ', '\n');
  text(randText, 10, frameCount*12);
}

```

for example i want to change just the second and fourth character " " not everyone, is it possible?

---

<div class="post-metadata">

### Author: ![Pr0tonX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pr0tonx/32/2590_2.png) [@Pr0tonX](https://discourse.processing.org/u/Pr0tonX)
#### Post date: [December 31, 2018, 3:40pm UTC](https://discourse.processing.org/t/text-go-to-the-next-line-after-finding-a-certain-character/7057/3 "2018-12-31T15:40:51Z")

</div>

Yes with insert() method :

```auto
sb.insert(index,"your text to add")

```

Take a look : [https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuffer.html](https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuffer.html)

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [December 31, 2018, 5:30pm UTC](https://discourse.processing.org/t/text-go-to-the-next-line-after-finding-a-certain-character/7057/4 "2018-12-31T17:30:15Z")

</div>

> [@bitCrasher](#):
>
> I’ve found this method StringBuffer,

It’s not a method, but a `class`: ☕

- [class / Reference / Processing.org](http://Processing.org/reference/class.html)
- [Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/StringBuffer.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/StringBuffer.html)

But since Java 5, we shouldn’t use StringBuffer anymore! We use the faster StringBuilder `class` instead: 🏗

- [StringBuilder (Java SE 11 & JDK 11 )](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/StringBuilder.html)

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [January 1, 2019, 12:08am UTC](https://discourse.processing.org/t/text-go-to-the-next-line-after-finding-a-certain-character/7057/5 "2019-01-01T00:08:21Z")

</div>

Did you look at split () ?

Makes your string to an array!

Then you can for loop over it.

Also: text() is also available with 5 parameters, so you have automatically a line break. Nice.
