Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Splitting a String of Characters

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 25, 2016 5:59 PM
(5949 views)

Hi! I want to parse a string of characters. I have 202 binary bits in my string and I want to cut that string in half. I believe I could find the length of the string and maybe get it to return the values at a certain number of characters. I'm just not sure how to actually use that to cut it in half and have two columns with 101 bits in each. And after I get that, I want to separate every bit into it's own column. So I want 101 columns of either a '1' or a '0' in it. I just don't know how to parse it by number of characters.

Thanks for any help!!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Try this

// input data is a string of character 1s and 0s representing bits

string = "11110000111000110010";

// split the string in two at the middle

// this substring starts at character 1 and goes for half the length

firsthalf = Substr( string, 1, Length( string ) / 2 );

// this substring starts just beyond the previous and the

// implicit length goes to the end

secondhalf = Substr( string, 1 + Length( string ) / 2 );

// the 1 and 0 bits go one per column

ncols = Length( firsthalf );

// start a fresh table

dt = New Table( "example" );

// add columns wtih names like "c3" for each bit

For( i = 1, i <= ncols, i++, // the || operator joins two strings

dt << New Column( "c" || Char( i ) ) // i is a number, char makes a string

);

// make a helper function to add bits to a row in dt

adddata = Function( {bits}, // parameter to function

{i, c}, // local variables

dt << addrows( 1 ); // function knows to use dt

For( i = 1, i <= Length( bits ), i++,

c = Column( dt, "c" || Char( i ) ); // same as above

dt:c = Num( Substr( bits, i, 1 ) ); // put bit in column

);

);

// each call to adddata puts a row of bits in dt

adddata( firsthalf );

adddata( secondhalf );

adddata( "1010101010" );

adddata( "1111111111" );

adddata( "0000000000" );

Craige

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Try this

// input data is a string of character 1s and 0s representing bits

string = "11110000111000110010";

// split the string in two at the middle

// this substring starts at character 1 and goes for half the length

firsthalf = Substr( string, 1, Length( string ) / 2 );

// this substring starts just beyond the previous and the

// implicit length goes to the end

secondhalf = Substr( string, 1 + Length( string ) / 2 );

// the 1 and 0 bits go one per column

ncols = Length( firsthalf );

// start a fresh table

dt = New Table( "example" );

// add columns wtih names like "c3" for each bit

For( i = 1, i <= ncols, i++, // the || operator joins two strings

dt << New Column( "c" || Char( i ) ) // i is a number, char makes a string

);

// make a helper function to add bits to a row in dt

adddata = Function( {bits}, // parameter to function

{i, c}, // local variables

dt << addrows( 1 ); // function knows to use dt

For( i = 1, i <= Length( bits ), i++,

c = Column( dt, "c" || Char( i ) ); // same as above

dt:c = Num( Substr( bits, i, 1 ) ); // put bit in column

);

);

// each call to adddata puts a row of bits in dt

adddata( firsthalf );

adddata( secondhalf );

adddata( "1010101010" );

adddata( "1111111111" );

adddata( "0000000000" );

Craige

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Splitting a String of Characters

Thank you! That helped a lot. Unfortunately that was just the beginning of what I wanted to do, and I'm not sure how to do that rest...

So I really need to indicate what half of the string I'm looking at. All 100 rows of strings I am splitting are for the same data, and all the first half strings have the same name, and so do the second half strings. And once I have that I need to graph both halves separately. When I tried to graph it manually in JMP, it did not turn out as I expected. How I have done this analysis is through Excel because it displayed the graph how I wanted it to be. Basically I just need all the new columns that the bits go into (in this case they are voltages) along the x-axis and the data along the y-axis

The only problem is that I couldn't figure out how to do that in JMP. Any help?

Thank you so much!!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Splitting a String of Characters

Generally there is a dependency between the way your data is organised and what a JMP platform will (or won't) give you.

I'm not sure I've understood what you are after completely, but if you add this code to Craige's above I think you will get close:

dt2 = dt << Transpose(

columns( :c1, :c2, :c3, :c4, :c5, :c6, :c7, :c8, :c9, :c10 ),

Output Table( "Transpose of example" )

);

dt2 << Graph Builder(

Show Control Panel( 0 ),

Variables(

X( :Label ),

Y( :Row 1 ),

Y( :Row 2 ),

Y( :Row 3 ),

Y( :Row 4 ),

Y( :Row 5 )

),

Elements( Position( 1, 1 ), Bar( X, Y, Legend( 12 ) ) ),

Elements( Position( 1, 2 ), Bar( X, Y, Legend( 13 ) ) ),

Elements( Position( 1, 3 ), Bar( X, Y, Legend( 15 ) ) ),

Elements( Position( 1, 4 ), Bar( X, Y, Legend( 23 ) ) ),

Elements( Position( 1, 5 ), Bar( X, Y, Legend( 27 ) ) )

);

You would have to adjust the values in column 'Label' to be the voltages, and you could do that with 'Recode' or through a little more JSL. Once you have what you want, it may be that there is a more direct way to get there.