Okay, so here’s an interesting challenge in TI-Basic. Does anyone know how to find and return the first occurrence of ANY character in a string, besides certain characters such as the [xbar] character and the space character specifically. I’m using a For( loop right now to loop through and check the string, but that is too slow for my needs. I know it’s very specific, but if you’ve got a quick and possibly even a one-line solution, let me know!
This probably isn't exactly what you want as it is still a For( loop. It runs pretty fast and ends as soon as it sees any other character. As long as you put Ans right after the loop runs you will have it stored for later use. Also, a little bit curious… what are you using this for? Hope this helps or you figure out something that will! :)
For(A,1,length(Str1
Sub(Str1,I,1
If Ans =!" " // you can add any characters that you want but I just put in space the =! is not equal to
Return
End
Ans
Yeah, I already am using a For( loop like that but the problem is I don’t like how the speed of the routine can vary depending on if there’s a bunch of spaces or xbars. I’m using this to display a bunch of note titles on the screen for my BasicNote CE program, and the point of the code is that it needs to skip over any leading line break characters (xbars) or spaces so the title can be the first line of actual text (if there is any, if not, I have a condition which takes care of that). For each note that has to be processed and get a title out of it, I am taking it from a large string with delimiters separating different notes and storing just the single note being processed temporarily into Str4.
Anyway, I was hoping for something more along the lines of inString(, but I’m not sure how to use it to get what I want without a loop.
This will find the first occurence of a specific set of characters, which isn't quite what you're asking for, but it may be useful
min(seq(inString(Str1,sub(Str2,I,1)),I,1,length(Str2)
Edit: I was right; This can be adapted to the opposite case; Finding the first occurrence that isn't in a set of characters. It makes use of the index-finder routine.
seq(inString(Str2,sub(Str1,I,1)),I,1,length(Str1))
1+sum(not(cumSum(Ans=0
That second one works great! Since you're using the seq( command it's still not really any faster than a For( loop or other loop, but I guess there's no way around that. I think I'll still use it in replacement of my code though, so thanks!
You could also try a while or repeat loop. Not sure if that will give much more speed though. Hope you can get it figured out! Sounds like a neat project!
Thanks! There's already a finished release I made 2.5 years ago if you're not aware, I'm just working on a new update now. You can follow along here if you like: cemete.ch/t14483