# Basic text manipulation - how?

**URL:** <https://community.n8n.io/t/basic-text-manipulation-how/9042>\
**Category:** Questions\
**Created:** [November 10, 2021, 3:29am UTC](https://community.n8n.io/t/basic-text-manipulation-how/9042 "2021-11-10T03:29:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shot](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/shot/32/8139_2.png) [@shot](https://community.n8n.io/u/shot)\
**Post date:** [November 10, 2021, 3:29am UTC](https://community.n8n.io/t/basic-text-manipulation-how/9042/1 "2021-11-10T03:29:29Z")

</div>

Greetings,

New n8n explorer here. Just dowloaded the Mac app and am tinkering using my local file system. I was able to copy a text file from one folder to another, but now I want to do a simple search and replace before saving.

Are there nodes for doing basic string manipulation, or must that be done with (eeeww) code? I don’t see anything like a simple find and replace node. Am I looking in the wrong place, or am I stuck with using JS?

-Steve

---

<div class="post-metadata">

**Author:** ![shot](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/shot/32/8139_2.png) [@shot](https://community.n8n.io/u/shot)\
**Post date:** [November 10, 2021, 6:07am UTC](https://community.n8n.io/t/basic-text-manipulation-how/9042/2 "2021-11-10T06:07:20Z")

</div>

I just want to copy a file and replace some text, and here’s my wf…

 ![n8n-copy-file](https://europe1.discourse-cdn.com/n8n/original/2X/2/244941c5a1ab6008ee00ec5e00fe132cfe6942bd.png)

```auto
// Code here will run only once, no matter how many input items there are.
// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.function

for (item of items) {

  const b64FileContents = item.binary.file.data;
  let txtFileContents = Buffer.from( b64FileContents, 'base64' ).toString( 'ascii' );
  txtFileContents = txtFileContents.replace( 'someText', 'otherText' );
  
  item.binary.file.data = Buffer.from( txtFileContents ).toString( 'base64' );
}

// You can write logs to the browser console
console.log('Done!');

return items;

```

This works, but is it the best approach? There appears to be no way to read a file as text - only binary. Any tips appreciated.

-Steve

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [November 10, 2021, 8:05am UTC](https://community.n8n.io/t/basic-text-manipulation-how/9042/4 "2021-11-10T08:05:23Z")

</div>

Hi @shot, welcome to the community 🎉

You could rid yourself of at least a bit of code by using the [Move Binary Data](https://docs.n8n.io/nodes/n8n-nodes-base.moveBinaryData/) node after your _Read Binary File_ node. In this example it moves the binary file content into the text JSON property:

 ![image](https://europe1.discourse-cdn.com/n8n/original/2X/9/95744f98685db79c3c2e4d5815878948c1a6db0d.png)

For the replace operation you’d still need to use a bit of code at this stage, but it would only be a single [expression](https://docs.n8n.io/nodes/expressions.html) when using the [Set](https://docs.n8n.io/nodes/n8n-nodes-base.set/) node for example.

 ![image](https://europe1.discourse-cdn.com/n8n/original/2X/7/7e152b32f991997a94b7234edc6c2298bbcc8cda.png) ![image](https://europe1.discourse-cdn.com/n8n/original/2X/8/883bf778c6eede843d9567934d2af0e128e4bfa2.png)

You can then move the result back using another _Move Binary Data_ node before writing it using the _Write Binary File_ node.

> **Example Workflow**
>

The above example workflow uses a Windows path, but I hope it still helps 😉

---

<div class="post-metadata">

**Author:** ![shot](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/shot/32/8139_2.png) [@shot](https://community.n8n.io/u/shot)\
**Post date:** [November 10, 2021, 1:36pm UTC](https://community.n8n.io/t/basic-text-manipulation-how/9042/5 "2021-11-10T13:36:50Z")

</div>

Super helpful! Thanks for taking the time!

I’ll need to study this and read up on expressions to really wrap my head around it. Might be back with questions.
