Suppose I type in a text box 02456, I want the 0 removed.
Suppose I type in a text box 024560, I want the 0 removed both sides.
Suppose I type in a text box 123456789 I want to replace 5 by 0
The only round about way I know is to convert the text string to a list and set the list index and make it whatever we want. I am sure there must be easier way to trim it or replace the letter in the text string. This is where I tried all possible ways and gave up.
https://x.thunkable.com/copy/ab2785aeaa26fe8e31839f54ac62bfe8
Please help
Start by Googling text Thunkable. You’ll find the documentation which includes various Text blocks. I think you’ll find the [replace all] block to be the most useful: Text - Thunkable Docs
You should not be using List blocks with text strings.
I played with it and it does not work. Infact this is a very good reference
But none could do what I want. Let me reword my questions
Given a text string say 2453635656 if I want to remove the digit at index 3 5 and 8 how would I do it?
Given a text string say 2453635656 if I want to replace the digit at #3 by 2, the digit at #5 by 1 and the digit at #8 by 4 how would I do it? All I need is some hint or a nudge in the right direction and I will put the effort. Thanks
I answered your question with a correct answer and you told me it doesn’t work (it does) and that you now have a different question. I’m not sure how to help you…
Also “it does not work” is not enough information. It’s best if you can provide a screenshot of the blocks you used.
If you use the Replace All block, you can replace the 0 with “” (empty string) and you can replace the 5 with a 0. That solves all three of your initial questions.
For your newer questions, you’ll have to play around with the Text blocks. But I can tell you that to replace digits at various places within a single text string, you’ll need to use a [text substring] block or a loop through all characters in the string (probably also with the text substring block).
Whew!! You are amazing Tatiang!! I am very heavily biased by C++ when I see this
My question is why is there a no set? Always get() set() go hand in hand, right? I have used replaceall() couple of times still the meaning it conveys is “all” and I am thinking, I want to replace 1 character at a particular index, this replaceall() will not work for me ? These biases prejudiced me from not thinking the Thunkable way. Sorry for the confusion I caused by my questions. I should have been precise and concise. Anyway here is my sample program and it works like a charm. Thanks again.
https://x.thunkable.com/copy/66f601b7e30d139893dcaaaee5ace9fe
I’m glad it’s working and I don’t think you should fault yourself for misinterpretting things based on your knowledge of C++. Thunkable is written in React Native and I don’t know how much C++ and React Native are similar (I’m much more comfortable with block-based coding but will occasionally stray into Javascript and… way back when in college, Pascal and even Assembly… BLAH). But I suspect that the developers of Thunkable had to take some liberties (or chose to take some liberties) when it comes to creating blocks that no- and lo-coders will understand. So that may throw you off a bit until you get used to it.
I think of the [replace all] block as equivalent to the find and replace (all) command in Google Docs, Word, etc.
And I agree that a [set letter] block would be helpful. I asked for something related a while back: Delete letter # block · Issue #1108 · thunkable/thunkable-issues · GitHub. You might consider adding a feature request to that GitHub list of issues.
Thanks and did it.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.