BBC BASIC for Windows
« addinstr/eatinstr ( Obsolete function ) »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:41pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: addinstr/eatinstr ( Obsolete function )  (Read 261 times)
michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
cheesy addinstr/eatinstr ( Obsolete function )
« Thread started on: Apr 4th, 2016, 06:18am »

Here is a link to a command that does what both these examples does, but better !!

http://bb4w.conforums.com/index.cgi?board=addins&action=display&num=1459759911

I will replace this post later with a better tool.
For now its history...

Lets say you have a string and you want to insert a letter or word in that string in a certain spot, (using the string that you feed this command)

The command : FN_addinstr(message$,location%,characterorstringtoinsert$)

If there was a command that did this... then I missed it.
(and didn't spend time looking hard enough for it)
Anyways.. I hope this helps someone.

The insertion point is at the chosen letter position
So.. if the location is 8 and your letter is p, then p is added to location 8 increasing the string size

Code:
      message$="I made  mistake. I really did !!"
      PRINT "This is the sentence that has a mistake"

      PRINT message$
      PRINT "1234567^"
      PRINT "So to make it simple (preserve the first 7 letters and add my letter or word at location 8"
      message$=FN_addinstr(message$,8,"a")
      PRINT
      PRINT "The correction :"
      PRINT
      PRINT message$
      PRINT "*************************************************************"
      PRINT "The incomplete word is AT"
      message$="AT"
      message$=FN_addinstr(message$,1,"C")
      PRINT "I added a C to location 1 and it becomes....."; message$
      PRINT "So to make it simple (preserve 0 letters and put C at the beginning of the string)"
      END
      REM Remember: when using this function, the left of your first letter in your string is 0...
      REM so if your word was AT ---  adding C to make it CAT ould need a plot location of 0
      DEF FN_addinstr(stringtomodify$,locationtoadd%,whatstring$)
      LOCAL lengthofstring%,rightlength%,leftword$,rightword$,finalword$
      lengthofstring%=LEN(stringtomodify$)
      rightlength%=lengthofstring%-locationtoadd%
      leftword$=LEFT$(stringtomodify$,locationtoadd%-1)
      rightword$=RIGHT$(stringtomodify$,rightlength%+1)
      finalword$=leftword$+whatstring$+rightword$
      =finalword$
 

And the next sample is for removing 1 letter from a string:

The command: FN_eatinstr(message$,location%)


At location 3 you would devour that letter"


Code:
      message$="DOHG"
      PRINT "This is the sentence that has a mistake"
      PRINT
      PRINT message$
      message$=FN_eatinstr(message$,3)
      PRINT
      PRINT "The correction :"
      PRINT
      PRINT message$
      END
      REM Remember: when using this function, the first letter in your string is 1...
      REM so if your word was DOHG, to change it to DOG you would set location to 3
      DEF FN_eatinstr(stringtomodify$,locationtoeat%)
      LOCAL lengthofstring%,rightlength%,leftword$,rightword$,finalword$
      lengthofstring%=LEN(stringtomodify$)
      rightlength%=lengthofstring%-locationtoeat%
      leftword$=LEFT$(stringtomodify$,locationtoeat%-1)
      rightword$=RIGHT$(stringtomodify$,rightlength%)
      finalword$=leftword$+rightword$
      =finalword$
 
« Last Edit: Apr 4th, 2016, 09:38am by michael » User IP Logged

I like making program generators and like reinventing the wheel
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls