March 28, 2024, 01:06:07 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Working with strings

Started by Andy, December 25, 2015, 11:16:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Some more good ideas Larry & Brian,

Thanks for inspiration and persperation!

I am now just past 200 and counting.

The numbers / doubles have been difficult but I'm winning!!

Keep downloading!

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

January 20, 2016, 11:02:04 PM #26 Last Edit: January 20, 2016, 11:05:27 PM by andy1966
Brian,

Forgot to answer your question about characters and words.

Yes you can.

There are commands:

SMCountChrs
Counts how many characters are in a string (same as len), however it has a ,1 optional switch this allows counting characters but does not include spaces.

Asrtring = "This is my string"

SMCountChrs(Astring,1)
Returns a count of 14 (count excludes spaces in this example).

SMCountChrsExcl(Astring,"my",1)
Returns a count of 12 (count excludes all instances of "my" and spaces in this example).

SMCountChrsExcl(Astring,"my")
Returns a count of 15 (count excludes "my" in this example).

SMCountWords(Astring) - counts how many words are in a line
Would return a value of 4 for Astring.

SMCountWordsExcl(Astring,"my")
Would return a value of 3 for Astring.
Counts how many words are in a line excluding all instances of "my".

I've got to nearly 220 functions now, and when I've tested them more (soon), I will release the latest update, until then It's StringTheory4.zip towards the end of page one of this post.

Thanks,
Andy.






Same as above, but you can specify a character or characters to exclude from the count.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Blimey! There's a lot there. Memo to oneself: Must read the manual!

Thanks, Andy

Brian

Andy

Brian,

Sorry forgot to say, these are in the next release which is coming real soon.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

January 22, 2016, 06:30:14 AM #29 Last Edit: January 22, 2016, 07:06:11 AM by andy1966
StringTheory5 is here....

What's new?

50 more functions which takes the running total up to 225!

I have worked on adding some more practical functions, including working with blocks of numbers and includes numbers with two decimal places (I shall increase that at some point).

It was very hard to work out some of these functions.

The library file code in now up to around 8,000 lines.

I've also incorporated many suggestions / wish list to help you all.

As always,  I have updated the help file, please read it first.

You can post any suggestions here of course, and I will look at them.

Best wishes,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Just an update for you.

I am now amending the String Theory code to include working with very very large numbers - which may of interest to you, even though you may not be intersted in just strings.

I can now add up two numbers (including decimal places), total size 1,024 digits (which I can increase).

I am now working on subtraction, multiplication and division.

I will post an update to the code when I've got there.

Andy.
:)
 
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

RitchieF

January 28, 2016, 07:30:10 AM #31 Last Edit: January 28, 2016, 07:55:33 AM by RitchieF
Hi Andy,
reading the command list in the help file I can't find the one command I'd need to parse nc-code line by line and extract different coordinates.
Here is a piece of nc-code :

G21
G80 G40 G17
M06 T216* 1. Carving
G90
M03 S5000 F250.
M08
G00 X-32.931 Y-29.599
G00 Z0.05
G01 Z-0.5 F100.
G03 X-43.895 Y-17.548 I-36.63 J-22.312 F250.
G03 X-60.544 Y-12.301 I-15.95 J-21.575
G01 X-60.79 Y-12.354
G03 X-61.466 Y-12.517 I1.444 J-7.482
G03 X-61.875 Y-12.747 I0.148 J-0.741
G03 X-61.884 Y-12.905 I0.139 J-0.087
G03 X-61.711 Y-13.103 I0.492 J0.255
G03 X-60.669 Y-13.645 I2.642 J3.807
G03 X-53.216 Y-18.217 I31.483 J42.951
G03 X-49.605 Y-19.389 I6.059 J12.53
G02 X-48.229 Y-19.712 I-3.063 J-16.149
G02 X-33.523 Y-29.892 I-8.76 J-28.366
G02 X-33.106 Y-30.482 I-36.099 J-25.975
G03 X-32.09 Y-31.911 I74.616 J51.981
G03 X-31.801 Y-32.181 I0.827 J0.595
G03 X-31.543 Y-32.246 I0.21 J0.288
G03 X-31.467 Y-32.183 I-0.031 J0.114
G03 X-31.45 Y-32.047 I-0.228 J0.097
G03 X-31.66 Y-31.526 I-1.414 J-0.267
G03 X-32.676 Y-29.953 I-9.017 J-4.711
G02 X-32.931 Y-29.599 I5.501 J4.225
G00 Z0.05
G00 X-65.511 Y-20.95
G01 Z-0.5 F100.

I'd like to extract i.e. the X-value, the Y-value, the I-value and the J-value from one line including the letter. I have a working solution but wanted to give your code a chance.
The problem is : not every nc-code has delimiters like spaces or colons.

Richard

LarryMc

QuoteThe problem is : not every nc-code has delimiters like spaces or colons.

Can you give an example of a few lines that
1) don't have spaces
and a few lines that
2) have colons?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RitchieF

Lines without spaces :

G00Z0.05
G01Z-0.5F100.
G03X-43.895Y-17.548I-36.63J-22.312F250.
G03X-60.544Y-12.301I-15.95J-21.575
G01X-60.79Y-12.354
G03X-61.466Y-12.517I1.444J-7.482
G03X-61.875Y-12.747I0.148J-0.741
G03X-61.884Y-12.905I0.139J-0.087
G03X-61.711Y-13.103I0.492J0.255
G03X-60.669Y-13.645I2.642J3.807
G03X-53.216Y-18.217I31.483J42.951
G03X-49.605Y-19.389I6.059J12.53

Colons

Colons was perhaps a wrong possibility for a delimiter. I mean actually every arbitrary delimiter a postprocessor might have used to split the axes or the other parameters from each other.

Richard

LarryMc

OK, a couple of other questions.

Is there any other circumstance that the letters 'X,Y,I,J' would appear in a line other than as you have shown; in a different order maybe?
or in some sort of a comment and if so how would that line be identified as being different?

and are there ever multiple instances of any of these letters ('X,Y,I,J' ) in a line? and are these the only letters/values you are interested in returning?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

January 29, 2016, 05:17:59 AM #35 Last Edit: January 29, 2016, 06:52:00 AM by andy1966
Hi Richard,

Attached is a very simple way to do it with StringMap.

My StringMap does not need delimiters to detect blocks of numbers, but the number blocks have to be sepatated by something (any other character that's not a number).

There are other ways with StringMap if you have multiple occurences of X,Y,J,I in each line (shown at the end of attachment 2).

Please let me know what you think.

Best wishes,
Andy.

:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

RitchieF

Andy, thanks for your code. Samples look fine. Gonna try it in my code.

Larry, in 2007 I wrote a script using AutoIt to wrap plane 2d nc-code onto a column. Please have a look here :

http://forum.vectric.com/viewtopic.php?f=2&t=656&p=8054#p8054

Meanwhile I have the same code running in IWBasic. Works fine and fast.

About the nc-code :

You will find every address code only once in a line. So I needed to extract the axis letter (X or Y coz it is 2d code) and grab the numbers behind the axis letter for later calculations.
Perhaps better visible in the script mentioned above.


Richard

LarryMc

Side note to Richard:
When I bought my Piranha CNC machine in came with Vetric VCarve DeskTop and I bought PhotoVCarve.  I can't afford the Pro version.  What I need is a really CHEAP, EASY TO USE program that will let me create 3D files I can carve.
But I still have  a lot to learn with what I got.

Your Praying Hands on a column are really neat.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RitchieF


Andy

January 30, 2016, 03:50:15 AM #39 Last Edit: January 30, 2016, 03:57:38 AM by andy1966
I noticed in the example strings Richard was showing that some of the numbers are actually minus?

So, just to cover this (if they are), I've updated the StringMap code with a new SMGetNumBlockX command.

This has now two optional parameters, one for including any minus sign that might be attached to a number block, and one for including x number of characters that preceeds the block.

I have attached my beta version of StringMap6, which includes the new SMGetNumBlockX command, plus many more functions, including a revised example for Richard (and any one else of course).

I've called it beta because there are one or two things I have not fully tested yet with large numbers, although adding and subtracting large numbers is there (as long as they are positive numbers - so far).

By the way... I found a bug in the Windows calculator (standard view), apparantly It's documented, but threw me for around 2 hours and left me doubting my old maths teachers!

Best wishes,
Andy.

P.S. like the CNC stuff!








Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

RitchieF

Andy,

counting the numerical blocks and adding X/Y/I or J might be the wrong way. Coz it is possible that a line has no X-coordinate or no Y-coordinate and the CNC control will use the coordinate from the previous line.

The right way is to search for X or Y and the extract the numerical value behind the letter if it exists.

Richard   

Andy

January 30, 2016, 05:21:38 AM #41 Last Edit: January 30, 2016, 05:25:36 AM by andy1966
No problem Richard, the previous examples can do it anyway, but you need to add a ,1 to be sure the value is not a minus (shown in example 3), and another ,1 to give you the letter.

You could then just use midstring to check what letter is at position 1 in the returned string.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

February 04, 2016, 05:27:03 AM #43 Last Edit: February 04, 2016, 05:43:03 AM by andy1966
StringMap 6 update....

I've now completed subtracting very large numbers (1024 digits).

It's taken some time as I realised there could (and will be at times) negative numbers to deal with including decimal place numbers (if there are any in either or both of the two numbers).

So the revised function SMSubNumBlockX (subtract two numbers, returns the correct value and includes a minus sign if the subtraction needs it) will be included in the next full upload.

I now need to add in working with negative numbers whilst adding two numbers together.

Once I've cracked the adding section, I will look at multiplication and division (if my maths are up to it).

Either way, both revised SMAddNumBlockX (add to numbers together) and SMSubNumBlockX functions will be added to the my next upload when completed.

Andy.
:)





Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy


I have now got addition working as well.

Attached is a screenshot (which you will probably be unimpressed by), however don't forget I am not able to work with such commands as you would normally e.g. INT, VAL, SETPRECISION etc...

So, I can now add up or subtract two numbers (each up to 1024 digits - including positive and negative values) and return the correct answer.

This is a labour of love, but if you like what I'm attempting - please tell me - it helps to keep me going!

Andy.



Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

You're in the same mode I was in when I was working on the new IDE for IWBasic.  You get on a roll and it's kinda hard to stop.
And a lot of times people don't realize how much effort you put into it.

The problem now is the the smaller number of active forum members is making it harder for there to be a person that suddenly has a major use for all your functions.  But it will come so I say that as long as it is fun for you; that you have the time; that the ideas keep coming; and your wife isn't saying she is leaving; then I say press on.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

February 05, 2016, 08:01:42 AM #46 Last Edit: February 05, 2016, 08:05:31 AM by andy1966
Larry,

Thanks for the keep going message - I think my other half is glad of it as I am out from under her feet.
;D

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Well, now I've been back to school to work out decimal places, I'm happy with the multiplication routine for my StringMap library file.

Attached is a screenshot of a multiplication of two numbers both 52 digits in length.

It did take a around four minutes to calculate, (something I will work on), but I guess if you want the answer, you will probably wait for it.

When I have division worked out I will release the next update.

Andy
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

How do you know that is the correct answer?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

By doing a very very very long manual calculation which takes a very very very long time!

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.