# Detecting highlighted text in a file

**URL:** https://discourse.processing.org/t/detecting-highlighted-text-in-a-file/4724
**Category:** Project Guidance
**Created:** [October 21, 2018, 6:40pm UTC](https://discourse.processing.org/t/detecting-highlighted-text-in-a-file/4724 "2018-10-21T18:40:12Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![destro](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@destro](https://discourse.processing.org/u/destro)
#### Post date: [October 21, 2018, 6:40pm UTC](https://discourse.processing.org/t/detecting-highlighted-text-in-a-file/4724/1 "2018-10-21T18:40:12Z")

</div>

hi all,

is it possible to be able to detect words highlighted in a text file? for instance, if i select “who” in text file, would i be able to save “who” in a variable?

thanks in advance,  
destro

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [October 23, 2018, 2:17pm UTC](https://discourse.processing.org/t/detecting-highlighted-text-in-a-file/4724/2 "2018-10-23T14:17:37Z")

</div>

I‘m not sure if this is what you Need, But you can Indeed detect highlighted Text within the processing Editor, but if this works in external Files… i don‘t know. And you can also add a Variable inside the Editor, by just adding Strings to the Editors Text. For example you could add to the first line of the Code the strings („int “ + name + „ = 0;“). This method is also used by the Formatter in the IDE, But as far as i‘m Aware of it can only be used by tools, not by a Sketch, But that might not be the case. I‘ll Look Up where the methods i‘m Talking about are and edit the post then^^ What i‘m Talking about is JavaTextarea.getDocument().insertString(int pos, int pos end, String text, null); You‘ll have to Look up the exact usage and all It’s methods to get it to do what you Need exactly.

---

<div class="post-metadata">

### Author: ![destro](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@destro](https://discourse.processing.org/u/destro)
#### Post date: [October 23, 2018, 2:30pm UTC](https://discourse.processing.org/t/detecting-highlighted-text-in-a-file/4724/3 "2018-10-23T14:30:37Z")

</div>

i haven’t been successful at figuring out where to start with this.

thanks, i’ll check out this function.

destro

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [October 23, 2018, 2:31pm UTC](https://discourse.processing.org/t/detecting-highlighted-text-in-a-file/4724/4 "2018-10-23T14:31:53Z")

</div>

BTW, it Starts from the Editor class, so it‘s more like Editor.getJavaTextArea(). And so on.

---

<div class="post-metadata">

### Author: ![destro](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@destro](https://discourse.processing.org/u/destro)
#### Post date: [October 23, 2018, 2:38pm UTC](https://discourse.processing.org/t/detecting-highlighted-text-in-a-file/4724/5 "2018-10-23T14:38:02Z")

</div>

i found what i was looking for with your nudge function:

> <https://stackoverflow.com/questions/15859289/how-to-make-selected-text-in-jtextarea-into-a-string>

thanks!  
destro.

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [October 23, 2018, 2:48pm UTC](https://discourse.processing.org/t/detecting-highlighted-text-in-a-file/4724/6 "2018-10-23T14:48:35Z")

</div>

Glad i could help you 😉
