Git Product home page Git Product logo

Comments (5)

gilmaimon avatar gilmaimon commented on May 24, 2024 1

Hi Den,
I'm glad to hear it's going well.

The returned object is an Arduino String. You should be able to access it just like a char array. You can also call .c_str() on the string and it will return you the underlying buffer.

Good luck and best regards,
Gil.

from arduinowebsockets.

denden4444 avatar denden4444 commented on May 24, 2024

Hi Gil
Thanks for the well wishes ;-)
Do you possibly have an example ?
Instead of String is there an existing char array that can be accessed ? This would save having to use more memory space to create extra variables for character field tests etc.

My incoming message looks like this :
# 100 test test 1234567890 1234567890 Normal 1234 12 1 1

I am currently testing and sorting first character (in the above example a # character) , based on result I decide what to do with the rest of the data.

I hope you can help
PS.
Not quite sure what you mean by this :
You can also call .c_str() on the string and it will return you the underlying buffer.

Kind regards
Den

from arduinowebsockets.

gilmaimon avatar gilmaimon commented on May 24, 2024

I mean you could do:

const char* raw_message_data = message.data().c_str();

And then use the char* as you did before.

Returning a char* might sound like a better idea but it has so many issues with memory management and ownership problems. I think it worth spending some efficiency in order to protect the user.

You could do:

auto data = message.data();

if (data[0] == '#') {
  // Do something
}

from arduinowebsockets.

denden4444 avatar denden4444 commented on May 24, 2024

Hi Gill

Thank you kindly for the advice and code bits .. experimenting as we speak :-)

Kind regards
Den

from arduinowebsockets.

gilmaimon avatar gilmaimon commented on May 24, 2024

:)

from arduinowebsockets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.