# Manipulating text

**URL:** <https://discourse.processing.org/t/manipulating-text/40843>\
**Category:** Project Guidance\
**Created:** [February 6, 2023, 10:22am UTC](https://discourse.processing.org/t/manipulating-text/40843 "2023-02-06T10:22:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![humus](https://avatars.discourse-cdn.com/v4/letter/h/e36b37/32.png) [@humus](https://discourse.processing.org/u/humus)\
**Post date:** [February 6, 2023, 10:22am UTC](https://discourse.processing.org/t/manipulating-text/40843/1 "2023-02-06T10:22:54Z")

</div>

Hi all,

I would like to manipulate a text with Processing in this way:

1. Enter a text from a file .doc or .odt;
2. Run this rule: place the last letter of the text at the beginning of the text and, than, swipe toward right all the letters maintaining the same puntuaction and word length
3. Save the new text as a new page .doc or .odt
4. Continue this rule until the text return to the original one.

Exemple :

1. He is tall, isn’t he? (original text inserted)
2. Eh ei stal, lis’n th? (new text with the rule applied and saved in a new page (step 3)
3. He he ista, lli’s nt? (the same rule in step 2 applied to the new text until the loop is closed).

Thanks!

Humus

---

<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:** [February 6, 2023, 3:49pm UTC](https://discourse.processing.org/t/manipulating-text/40843/2 "2023-02-06T15:49:50Z")

</div>

Start by using `split(..., " ")` or splitTokens to break the sentence into words.

Each word could be placed in a class Word.

You can have an array of Word.

The class would have methods:

- removeLastLetter (starting at last word) returns a char, e in Example 1
- AddLetterAtStart

**Pseudo code**

```auto
char firstLetter = array[last entry].removeLastLetter(); 

for (int i...) {
   array[i].AddLetterAtStart(firstLetter); 
   firstLetter = array[i].removeLastLetter(); 
}

```

In the methods you have to skip the special signs like , ’

---

<div class="post-metadata">

**Author:** ![JoseMY](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josemy/32/2016_2.png) [@JoseMY](https://discourse.processing.org/u/JoseMY)\
**Post date:** [February 8, 2023, 10:06pm UTC](https://discourse.processing.org/t/manipulating-text/40843/3 "2023-02-08T22:06:18Z")

</div>

If you are using p5.js, take a look on the documentation for “regular expressions”. They can help you split on both spaces and punctuators.

For the “open a word document” part, I don’t know if you can import a word reading class from other library (hummm… libreoffice?). That would work on java mode only.
