Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ Programming
➜ General
➜ Combining Variables
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| DB
(3 posts) Bio
|
Date
| Tue 05 Mar 2019 02:18 AM (UTC) Amended on Tue 05 Mar 2019 02:48 AM (UTC) by DB
|
Message
| Apologies in advance for the newbie question! Congrats on the Regexp library it is really useful!
My problem is if I match a message in quotes like ms.Match("63 100") my code works perfectly.
But I'd like to declare a variable in the beginning of the code so I don't need to change the values in the loop.
In the beginning of my code I'm declaring a variable like this:
char address = 63;
Then in the loop I want to match something like:
ms.Match (address, "100");
But as you know it does not work, I can't seem to find the right meta-character formatting to make it work.
Any suggestions please? | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Tue 05 Mar 2019 04:46 AM (UTC) |
Message
| Use sprintf to make the thing you want to match on, and then pass that string to ms.Match.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| DB
(3 posts) Bio
|
Date
| Reply #2 on Tue 05 Mar 2019 11:19 AM (UTC) Amended on Tue 05 Mar 2019 11:20 AM (UTC) by DB
|
Message
| Thank you!
But then would I be creating a buffer with just two characters? Am I missing something? | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Tue 05 Mar 2019 11:06 PM (UTC) |
Message
| No, the buffer would have in it: 63 100
That’s what you want to match on isn’t it? In any case can’t use you strstr if you just want to find if one string is inside another?
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| DB
(3 posts) Bio
|
Date
| Reply #4 on Wed 06 Mar 2019 11:39 AM (UTC) Amended on Wed 06 Mar 2019 11:40 AM (UTC) by DB
|
Message
| Just because I didn’t know you could do that! Newbieism is a serious condition but I’m treating it! : )
Thanks Nick! | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,864 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top