# How to trim a text box or replace a single letter at a specific index?

**URL:** <https://community.thunkable.com/t/how-to-trim-a-text-box-or-replace-a-single-letter-at-a-specific-index/2278076>\
**Category:** Questions about Thunkable X\
**Created:** [February 15, 2023, 5:33am UTC](https://community.thunkable.com/t/how-to-trim-a-text-box-or-replace-a-single-letter-at-a-specific-index/2278076 "2023-02-15T05:33:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anandavardhana57zwwl](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anandavardhana57zwwl](https://community.thunkable.com/u/anandavardhana57zwwl)\
**Post date:** [February 15, 2023, 5:33am UTC](https://community.thunkable.com/t/how-to-trim-a-text-box-or-replace-a-single-letter-at-a-specific-index/2278076/1 "2023-02-15T05:33:33Z")

</div>

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](https://x.thunkable.com/copy/ab2785aeaa26fe8e31839f54ac62bfe8)  
Please help

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 15, 2023, 5:35am UTC](https://community.thunkable.com/t/how-to-trim-a-text-box-or-replace-a-single-letter-at-a-specific-index/2278076/2 "2023-02-15T05:35:25Z")

</div>

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](https://docs.thunkable.com/text#replace-all)

You should not be using List blocks with text strings.

---

<div class="post-metadata">

**Author:** ![anandavardhana57zwwl](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anandavardhana57zwwl](https://community.thunkable.com/u/anandavardhana57zwwl)\
**Post date:** [February 15, 2023, 5:43am UTC](https://community.thunkable.com/t/how-to-trim-a-text-box-or-replace-a-single-letter-at-a-specific-index/2278076/3 "2023-02-15T05:43:45Z")

</div>

I played with it and it does not work. Infact this is a very good reference

> [@Tips for working with text](https://community.thunkable.com/t/tips-for-working-with-text/154482/2):
>
> Is Empty The is empty block can be used to check whether or not a string, or piece of text, contains and characters. This block returns true if there are no characters in the string and returns false if there is one or more characters in a string. [isEmpty] Example 1 In this example we want to make sure that the user has typed something into Text\_Input1. There are a couple of ways to do this. These blocks do nothing if Text\_Input1 is empty and only greet the user if they have typed in the t…

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

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 15, 2023, 5:54am UTC](https://community.thunkable.com/t/how-to-trim-a-text-box-or-replace-a-single-letter-at-a-specific-index/2278076/4 "2023-02-15T05:54:10Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![anandavardhana57zwwl](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anandavardhana57zwwl](https://community.thunkable.com/u/anandavardhana57zwwl)\
**Post date:** [February 15, 2023, 8:46pm UTC](https://community.thunkable.com/t/how-to-trim-a-text-box-or-replace-a-single-letter-at-a-specific-index/2278076/5 "2023-02-15T20:46:29Z")

</div>

Whew!! You are amazing Tatiang!! I am very heavily biased by C++ when I see this  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/6/7688192a387702a52c4eeb01b8e6edf9f0668801.png)  
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](https://x.thunkable.com/copy/66f601b7e30d139893dcaaaee5ace9fe)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 15, 2023, 10:22pm UTC](https://community.thunkable.com/t/how-to-trim-a-text-box-or-replace-a-single-letter-at-a-specific-index/2278076/6 "2023-02-15T22:22:51Z")

</div>

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](https://github.com/thunkable/thunkable-issues/issues/1108). You might consider adding a feature request to that GitHub list of issues.

---

<div class="post-metadata">

**Author:** ![anandavardhana57zwwl](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anandavardhana57zwwl](https://community.thunkable.com/u/anandavardhana57zwwl)\
**Post date:** [February 16, 2023, 12:02am UTC](https://community.thunkable.com/t/how-to-trim-a-text-box-or-replace-a-single-letter-at-a-specific-index/2278076/7 "2023-02-16T00:02:56Z")

</div>

Thanks and did it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [May 17, 2023, 12:03am UTC](https://community.thunkable.com/t/how-to-trim-a-text-box-or-replace-a-single-letter-at-a-specific-index/2278076/8 "2023-05-17T00:03:21Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
