? Yarn - String Function Library ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Yarn - String Function Library

Submitted
Updated
Author
snail_
Public Key
Q33J44BD
Min. Compat.
All
Version
1.0
Rating
10 votes
Description Yarn is a library which provides various string processing functions. All functions return new strings and will not taint the inputs. Instructions SPLIT$(string$,separator$) Splits string$ into substrings at each occurrence of separator$ and returns a new string array containing every substring (including empty ones.) If separator$ is the empty string, the output array is the list of every character in the string. Commonly used with JOIN$(). DIM OUT$[0] OUT$=SPLIT$("HELLO WORLD"," ") FOR I%=0 TO LEN(OUT$)-1 PRINT OUT$[I%] NEXT This is a function which returns an array, which usually isn't standard practice in SB. Use carefully. JOIN$(array$[],separator$) Returns a new string by joining all of the entries in array$[] together, with separator$ placed between them. Commonly used with SPLIT$(). DIM IN$[3] COPY IN$,@FRUIT PRINT JOIN$(IN$,",") 'APPLE,BANANA,ORANGE @FRUIT DATA "APPLE","BANANA","ORANGE" REPLACE$(string$,old$,new$) Returns a new version of string$ where all occurrences of old$ are replaced with new$. PRINT REPLACE$("HELLO WORLD","L","Q") 'HEQQO WORQD COUNT(string$,substring$) Returns the number of times substring$ occurs in string$, as an integer. PRINT COUNT("AABAA","A") '4 UPPER$(string$) Returns a new version of string$ where every lowercase letter is uppercase. Does not touch any other characters. Supports most (if not all) alphabets in SB's character set. PRINT UPPER$("Hello wORLD") 'HELLO WORLD LOWER$(string$) Returns a new version of string$ where every uppercase letter is lowercase. Does not touch any other characters. Supports most (if not all) alphabets in SB's character set. PRINT LOWER$("Hello wORLD") 'hello world REVERSE$(string$) Returns a backwards version of string$. PRINT REVERSE$("HELLO WORLD") 'DLROW OLLEH TRIM$(string$) Returns a version of string$ with leading and trailing whitespace removed. Whitespace characters are tab, space, linefeed, and carriage return. PRINT TRIM$(" A ") 'A REST$(string$,start%) Returns the rest of string$ starting at start%. In other words, returns a substring of string$ which starts at start% and runs to the end of the string. PRINT REST$("HELLO WORLD",6) 'WORLD
Categories
Keywords
  • yarn
  • string
  • library
6 Comment(s) Y_ack Y_ack feed me ropes snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! Night Person I like the quiet night and sleep late. Express Yourself Rope - Yarn Function Library Y_ack Y_ack I meant ropes actually. Simeon Simeon Scholar Received for knowing a great deal about programming topics Achievements Amazing Page Hidden Achievements Drawing I like to draw! Hobbies The Public Key does not work. Also, I found a very elegant approach to some of these, I don't know if you are using them, but these are fast algorithms that avoid excessive string operations, you should consider them, or at least look at the code: DEF COUNT(S$,C$) VAR N=-1,I REPEAT I=INSTR(I,S$,C$)+1 N=N+1 UNTIL !I RETURN N END DEF TRIM$(S$) IF !LEN(S$) THEN RETURN "" VAR I,J=LEN(S$)-1 WHILE S$[I]==" " I=I+1 WEND WHILE S$[J]==" " J=J-1 WEND RETURN MID$(S$,I,J-I+1) END snail_ snail_ Helper Received for being very helpful around SmileBASIC Source Achievements OSP Contest 2 Contest Participant I participated in the second SmileBASIC Source OSP Contest! Night Person I like the quiet night and sleep late. Express Yourself Sorry about that; wound up typoing the key without checking, which means nobody was able to download this the entire time… :P And yeah, that's more or less what my code looks like. Any suggestions are entirely welcome of course. banana banana RNG Hidden Easter Eggs Disguised Hidden Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength i love it