BBC BASIC for Windows
« The better string edit function (TOOL)Fixed I hope »

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: The better string edit function (TOOL)Fixed I hope  (Read 372 times)
michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx The better string edit function (TOOL)Fixed I hope
« Thread started on: Apr 4th, 2016, 08:51am »

Ok this needs testing. Its not ready (please let me know if it has issues)

FN_editstr(message$,location,string$)

If the example string$: has an empty string "" then you would remove a letter from message$ at the location specified

If the example: string$ has a character (or word) then it will add that letter (or word) to the location specified..
Code:
      tv%=0
      message$="DOHG"
      PRINT "This is the word that has a mistake:"
      PRINT
      PRINT message$
      message$=FN_editstr(message$,3,"")
      PRINT
      PRINT "The correction :"
      PRINT message$
      PRINT
      PRINT "*************************************************************"
      PRINT "The incomplete word is AT"
      message$="AT"
      message$=FN_editstr(message$,1,"C")
      PRINT "I added a C to location 1 and it becomes....."; message$
      PRINT" *************************************************************"
      PRINT
      PRINT "getting the character out of the string that doesnt match and replacing it with a Z"
      PRINT
      message$="**********E**********"
      PRINT message$
      message$=FN_editstr(message$,11,""):REM should be at the same location when I replace it
      PRINT message$
      message$=FN_editstr(message$,11,"Z"):REM the string should be exactly the same except for the Z
      PRINT message$
      PRINT
      PRINT "1) print the original message"
      PRINT "2) print the message with the removed E"
      PRINT "3) Replace the E with Z and display it"
      PRINT "It looks like this command works"
      PRINT "The offending letter is extracted and replaced by Z at location 11, so this tool appears to be working properly"
      PRINT "*******************************************************************************************************"
      PRINT "Now lets clip the sides of the message"
      PRINT "Now Z has 9 stars on each side"
      message$=FN_editstr(message$,1,"")
      tv%=LEN(message$)
      message$=FN_editstr(message$,tv%,"")
      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_editstr(stringtomodify$,location%,whatstring$)
      LOCAL lengthofstring%,rightlength%,leftword$,rightword$,finalword$
      lengthofstring%=LEN(stringtomodify$)
      rightlength%=lengthofstring%-location%
      leftword$=LEFT$(stringtomodify$,location%-1)
      IF whatstring$="" THEN
        rightword$=RIGHT$(stringtomodify$,rightlength%)
        finalword$=leftword$+rightword$
      ENDIF
      IF whatstring$<>"" THEN
        rightword$=RIGHT$(stringtomodify$,rightlength%+1)
        finalword$=leftword$+whatstring$+rightword$
      ENDIF
      =finalword$
 

« Last Edit: Apr 4th, 2016, 1:20pm by michael » User IP Logged

I like making program generators and like reinventing the wheel
Zaphod
Guest
xx Re: The better string edit function (TOOL)Fixed I
« Reply #1 on: Apr 4th, 2016, 4:40pm »

I can't think how you would use this in a program but...
It can be made simpler yet:
Code:
      DEF FN_editstr(stringtomodify$,location%,whatstring$)
      LOCAL rightlength%,leftword$,rightword$
      rightlength%=LEN(stringtomodify$)-location%
      leftword$=LEFT$(stringtomodify$,location%-1)
      IF whatstring$="" THEN rightword$=RIGHT$(stringtomodify$,rightlength%) ELSE rightword$=RIGHT$(stringtomodify$,rightlength%+1)
      =leftword$+whatstring$+rightword$
 


Or for a Library you would keep it compact, say
Code:
      DEF FN_editstr(a$,I%,s$)
      LOCAL rl%
      rl%=LEN(a$)-I%
      IF s$<>"" rl% +=1
      =LEFT$(a$,I%-1)+s$+RIGHT$(a$,rl%)
 
« Last Edit: Apr 4th, 2016, 5:28pm by Zaphod » User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: The better string edit function (TOOL)Fixed I
« Reply #2 on: Apr 4th, 2016, 7:51pm »

Its more for creating special interface controls. For instance, in graphics.

A virtual text interface would require this function for editing.
Especially, if you were wanting to edit with the mouse like in a normal editor.


This may come in handy if you don't want anything controlling your interface while playing a game. The text interface could be live with the game..
(game keeps playing while the text is being monitored)

Someone out there might find a need for that. But its mostly just covering a unused base and its also part of a long list of special tools I need to make.

By the time I am done. I probably could have completely learned windows system commands and (maybe) could have done the same things..

Why do I keep thinking that the windows sys commands might not be up to the task for what I am doing?
I am not sure.. but I am determined.
« Last Edit: Apr 4th, 2016, 7:59pm by michael » User IP Logged

I like making program generators and like reinventing the wheel
Zaphod
Guest
xx Re: The better string edit function (TOOL)Fixed I
« Reply #3 on: Apr 4th, 2016, 8:29pm »

Quote:
(game keeps playing while the text is being monitored)


You do realize that BBC for Windows runs in a single thread don't you?
User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: The better string edit function (TOOL)Fixed I
« Reply #4 on: Apr 4th, 2016, 9:12pm »

Yeah. maybe I am wasting my time.

I am putting this on hold and studying the windows interface commands.
1) my text control must always be active
2) it must be able to be edited
3) I must be able to use the information typed
4) the text area must not require a mouse click to activate it
5) the text area must be able to accept program line insertion if say I load a program or data or say I am sending a computer response to the same box.
6) the game or IDE or whatever the program is doing must be running while the text is active.

Can you show me an example of a small one line text box that allows me to insert one line commands or text that I can get a string from and place this nice custom size box anywhere on my graphics screen like in a game?
« Last Edit: Apr 4th, 2016, 10:02pm 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