Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8117379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:08:55+00:00 2026-06-06T04:08:55+00:00

I tried to split two fields from a binary string: -define(S,<<M\0\0\0522039355099,010100000008,0,010170000000,0,0,0,0,0,0,,,0,0,,‌​0110,00,150,0,0,0\0>>).<<Message_length:4/binary,Msg/binary>> = S. the

  • 0

I tried to split two fields from a binary string:

-define(S,<<"M\0\0\0522039355099,010100000008,0,010170000000,0,0,0,0,0,0,,,0,0,,‌​0110,00,150,0,0,0\0">>).<<Message_length:4/binary,Msg/binary>> = S.

the first 4 bytes are the length of the following message, the other byte are the message,
a null byte terminates the string.

The result is:
** exception error: o match of right hand side value
EDIT
Just before the given code, there is:

[Sequence|Reste] = binary:split(T,<<"\0">>),

Does “Reste” bounded ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:08:57+00:00Added an answer on June 6, 2026 at 4:08 am

    Your code is ok, so either you dont have a binary string, or the length of Mystring does not comply with the pattern. Here’s a quick test:

    1> Mystring = <<"abcde">>.
    <<"abcde">>
    2> <<Message_length:4/binary,Msg/binary>> = Mystring.
    <<"abcde">>
    3> Message_length.
    <<"abcd">>
    4> Msg.
    <<"e">>
    

    If you have a string (a list of integers) instead of a binary string (<<“string”>>), as Vincenzo suggested, call erlang:list_to_binary/1 first.

    Hope it helps

    EDIT: I’ve checked the example string you left in a comment of Vincenzo’s answer. I’ve tried it with your code and still works. Is it possible that Message_length and/or Msg are already bound (and different to Mystring) when reaching that line of code? That would make the pattern matching fail.

    EDIT2: Tested with the updated data in the question:

    1> S = <<"M\0\0\0522039355099,010100000008,0,010170000000,0,0,0,0,0,0,,,0,0,,\342\200\214\342\200\2130110,00,150,0,0,0\0">>.
    <<77,0,0,42,50,48,51,57,51,53,53,48,57,57,44,48,49,48,49,
      48,48,48,48,48,48,48,56,44,48,...>>
    2> <<Message_length:4/binary,Msg/binary>> = S.
    <<77,0,0,42,50,48,51,57,51,53,53,48,57,57,44,48,49,48,49,
      48,48,48,48,48,48,48,56,44,48,...>>
    3> Message_length.
    <<77,0,0,42>>
    4> Msg.
    <<"2039355099,010100000008,0,010170000000,0,0,0,0,0,0,,,0,0,,\342"...>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to split a string in a linq query. I got an error
I'm trying to split a string into two different words. I have the following
I have a large (3GB), gzipped file containing two fields: NAME and STRING. I
how can I split this barcode by group separator with Progress? I've tried chr(29)
Tried examples from 'php.net' but don't understand what's the problem. Any suggestions? <?php $_SESSION['test']
In my application, I have two queries that occur from time to time (from
I'm trying to split a table in two views depending on whether the field
I'm changing the center point on a google map by either two dropdown fields,
I want to split two combined strings. First characters are upper char like FirstnameSurname.
I want to have a layout that is split in two parts vertical .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.