? SUBST$ replacement using [ ] ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
Creep into the Halloween / Horror Programming Contest (Deadline Extended)

SUBST$ replacement using [ ]

string$[I] == MID$(string$,I,1) string$[I]=replace$ == string$=SUBST$(string$,I,1,replace$) So, for example: S$="ABC" S$[1]="" ?S$ AC
Author
12Me21
Updated
Rating
4 votes
Categories
Keywords
8 Comment(s) 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS I've gotten so used to this feature that it's really annoying to deal with other langauges like JavaScript that don't have mutable strings. 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS for example, if you want to remove spaces you might do NEWSTRING$="" FOR I=0 TO LEN(STRING$)-1 IF MID$(STRING$,I,1)!=" " THEN NEWSTRING$=NEWSTRING$+MID$(STRING$,I,1) NEXT or better yet: FOR I=0 TO LEN(STRING$)-1 IF STRING$[I]==" " THEN STRING$=SUBST$(STRING$,I,"",1):DEC I NEXT but the best way is: FOR I=0 TO LEN(STRING$)-1 IF STRING$[I]==" " THEN STRING$[I]="" NEXT (it seems so obvious, why is this not more well known) SquareFingers SquareFingers Uh, no. The "best way" is not the best way, it is broken. If two spaces are in a row, only one will be removed. How about: WHILE (INSTR(STRING$," ")>=0) STRING$[INSTR(STRING$," ")]="" WEND 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS oops, I meant to add DEC I I bet INSTR is pretty slow 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS FOR I=0 TO LEN(STRING$)-1 IF STRING$[I]==" " THEN STRING$[I]="':DEC I NEXT SquareFingers SquareFingers I bet INSTR is pretty slow How much do you bet? calc84maniac calc84maniac OSP Contest 1 Winner I won the first SmileBASIC Source OSP Contest! Programming Contest Amazing Page Hidden Achievements Scholar Received for knowing a great deal about programming topics Achievements I would say calling it twice like that is slower than it should be. And you can also avoid searching characters you've already searched. I%=0 REPEAT I%=INSTR(I%,STRING$," ") IF I%<0 THEN BREAK STRING$[I%]="" UNTIL FALSE 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS S$=" HELL O! !!" [email protected] WHILE I+1S$[I]=""@M I=INSTR(I,S$," ")WEND ?S$ I found a use for GOTO ...