# Extract a part of string from a payload

**URL:** <https://discourse.nodered.org/t/extract-a-part-of-string-from-a-payload/74251>\
**Category:** General\
**Created:** [27 January 2023 12:44 UTC](https://discourse.nodered.org/t/extract-a-part-of-string-from-a-payload/74251 "2023-01-27T12:44:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fef\_38](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fef_38/32/40902_2.png) [@Fef\_38](https://discourse.nodered.org/u/Fef_38)\
**Post date:** [27 January 2023 12:44 UTC](https://discourse.nodered.org/t/extract-a-part-of-string-from-a-payload/74251/1 "2023-01-27T12:44:35Z")

</div>

Form my LoRa Module I receive the ascii buffer:  
msg.payload = Buffer.from("240E5048556D366420A262000026200F00AA7400", "hex")  
In this buffer I have a DevEUI from the module : E5048556D366420  
I would like to save this DevEUI in the variable (ID = E5048556D366420)  
How can I process? (without to use the node “buffer parser”)  
Thank for the future answer…

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 January 2023 11:44 UTC](https://discourse.nodered.org/t/extract-a-part-of-string-from-a-payload/74251/2 "2023-01-28T11:44:14Z")

</div>

> [@Fef\_38](#):
>
> I would like to save this DevEUI in the variable (ID = E5048556D366420)

You can use `toString("hex")` to convert the buffer to a string like the one you started with, and then use `substring()` to extract the part you want.

---

<div class="post-metadata">

**Author:** ![Fef\_38](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fef_38/32/40902_2.png) [@Fef\_38](https://discourse.nodered.org/u/Fef_38)\
**Post date:** [28 January 2023 20:42 UTC](https://discourse.nodered.org/t/extract-a-part-of-string-from-a-payload/74251/3 "2023-01-28T20:42:37Z")

</div>

Thank you for your answer...  
I used the routine bellow:

var Buf = Buffer.from(mes, "hex");  
var val = Buffer.from([Buf[1], Buf[2], Buf[3], Buf[4], Buf[5], Buf[6], Buf[7],Buf[8]]);  
var ID = val.toString('hex');

And works.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [28 January 2023 20:57 UTC](https://discourse.nodered.org/t/extract-a-part-of-string-from-a-payload/74251/4 "2023-01-28T20:57:17Z")

</div>

@Fef_38

I _think_ you can optimise this somewhat.

```javascript
var Buf = Buffer.from(mes, "hex").slice(1,8);
var ID = Buf.toString('hex');

```

---

<div class="post-metadata">

**Author:** ![Fef\_38](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fef_38/32/40902_2.png) [@Fef\_38](https://discourse.nodered.org/u/Fef_38)\
**Post date:** [28 January 2023 21:19 UTC](https://discourse.nodered.org/t/extract-a-part-of-string-from-a-payload/74251/5 "2023-01-28T21:19:05Z")

</div>

Thank you, it works well...  
I am a beginner in Node-RED (Node.js) and I don't know all the "subtleties"!

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [28 January 2023 21:35 UTC](https://discourse.nodered.org/t/extract-a-part-of-string-from-a-payload/74251/6 "2023-01-28T21:35:35Z")

</div>

Plenty of us here!  
Researching the answers given, gaining an understanding on the solutions schematic will go a long way!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 March 2023 21:36 UTC](https://discourse.nodered.org/t/extract-a-part-of-string-from-a-payload/74251/7 "2023-03-29T21:36:15Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
