# Reading parts of string with 20 numbers

**URL:** https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989
**Category:** Ask for Help
**Created:** [July 23, 2020, 12:50pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989 "2020-07-23T12:50:01Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)
#### Post date: [July 23, 2020, 12:50pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/1 "2020-07-23T12:50:01Z")

</div>

Hi, my user add a string of 47 numbers reading from codebar. I have to follow a layout and take parts of this string to get the type of information, for instance, the first 3 numbers.  
From the 4th to 10th get the amount, from the Xth to Xth character take a date.

What type of column can I use to get these three information and write each one in a column?  
Tkx

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [July 23, 2020, 1:25pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/2 "2020-07-23T13:25:07Z")

</div>

I think you need to bring that back to the sheet and use Left, Mid & Right functions to separate the string to what you want. It would be the easiest way.

---

<div class="post-metadata">

### Author: ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)
#### Post date: [July 23, 2020, 1:30pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/3 "2020-07-23T13:30:17Z")

</div>

Tkx so much for your prompt reply. I´ve tried it using arrayformula, but it didnt work.  
It means that we someone add a new row I have to drag down the formula.

Tkx again!

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [July 23, 2020, 2:13pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/4 "2020-07-23T14:13:03Z")

</div>

Can you share a sheet with sample data and desired outcome? I will try to have a go for you later when I have time.

---

<div class="post-metadata">

### Author: ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)
#### Post date: [July 23, 2020, 2:24pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/5 "2020-07-23T14:24:53Z")

</div>

Thx for your kindness [https://bit.ly/2WOLCz4](https://bit.ly/2WOLCz4)

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [July 23, 2020, 2:47pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/6 "2020-07-23T14:47:58Z")

</div>

Can you specify which part of the string corresponds to which information, I will try to extract them one by one.

---

<div class="post-metadata">

### Author: ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)
#### Post date: [July 23, 2020, 5:28pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/7 "2020-07-23T17:28:53Z")

</div>

the two importants are the first digit should be 8 and the middle when I use this formula value(MID(A3:A;5;7)&mid(A3:A;13;2)&","&mid(A3:A;15;2)))

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [July 24, 2020, 10:36am UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/8 "2020-07-24T10:36:59Z")

</div>

So let’s say from a string like this.

846800000014329502962020006100380002002643171602

You want to get 3 fields:

- 0000001
- 32
- 95

Is it correct?

---

<div class="post-metadata">

### Author: ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)
#### Post date: [July 24, 2020, 6:45pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/9 "2020-07-24T18:45:36Z")

</div>

The other digits tell me other info. But yes, the 2 main information are amount and type of record.  
In this case, I need to check if this sequence starts with 8 and another check from 5th take seven digits, after from 13th take 4 digits.

in your example **8** 468 **0000001** 4 **3295** 02962020006100380002002643171602  
8 as first digit OK  
the amount will be 132,95

---

<div class="post-metadata">

### Author: ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)
#### Post date: [July 26, 2020, 3:37am UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/10 "2020-07-26T03:37:38Z")

</div>

Man, with your valuable tip about trigger, I’m gonna try to write a script to review this string after user save. right?

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [July 26, 2020, 3:42am UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/11 "2020-07-26T03:42:27Z")

</div>

I’m gonna write a formula for you tomorrow when I got home. Away from the computer today 😂

---

<div class="post-metadata">

### Author: ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)
#### Post date: [July 26, 2020, 2:57pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/12 "2020-07-26T14:57:22Z")

</div>

Tkx again! Of course we have many ways to solve and my easier way I copy the formula of the cell above. So I set the Google Sheet formula using MID, Left and now when user add another row I just copy the formula above.

Feel free for sharing another better way (of course).  
But your help was amazing!

---

<div class="post-metadata">

### Author: ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)
#### Post date: [July 26, 2020, 3:21pm UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/13 "2020-07-26T15:21:18Z")

</div>

Oh My! Yesterday everything run fine! Today I just add to “onchange function” the script to copy the formula and nothing happen. I guess my trigger stopped. any tip?

I enabled notification I’m analyzing what´s wrong.  
Now I’m receving…  
|7/26/20 10:54 PM|onChange|Exception: Cell reference out of range|change|7/26/20 10:54 PM|

---

<div class="post-metadata">

### Author: ![Alexandre\_Caruso](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/alexandre_caruso/32/6240_2.png) [@Alexandre\_Caruso](https://community.glideapps.com/u/Alexandre_Caruso)
#### Post date: [July 27, 2020, 2:48am UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/14 "2020-07-27T02:48:34Z")

</div>

YES!! After hours studying, reading StackOverFlow, watching YT videos I got it!  
Let´s go to another challenges.

Just for records  
var lastRow = ss.getLastRow();  
var lastColumn = ss.getLastColumn();

Logger.log(lastRow);  
Logger.log(lastColumn);  
//var lastCell = e.source.getActiveSheet().getRange(lastRow, lastColumn);

var LinhaDigitavel = ss.getRange(lastRow,1).getValue();  
Logger.log(LinhaDigitavel);

// valida primeiro caracter da LinhaDigitavel  
ss.getRange(lastRow,5).setValue(LinhaDigitavel[0]);

// copia a fórmula do valor da célula anterior  
//UltimaFormula = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(lastRow-1,4).getFormula();  
CelulaDestino = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange(lastRow,4);  
Logger.log(CelulaDestino);

ss.getRange(lastRow-1,4).copyTo(CelulaDestino);  
[//ss.getRange](https://ss.getRange)(lastRow,4).setValue(UltimaFormula).setNumberFormat(“Currency”);  
}

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [July 27, 2020, 2:55am UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/15 "2020-07-27T02:55:13Z")

</div>

Hi Alex,

I have made a sample sheet for you: [https://docs.google.com/spreadsheets/d/1sEQHpSKyHx9w2F\_Xx3lm56SU1p-8eI81OYU5TYvQFvw/edit#gid=1520352505](https://docs.google.com/spreadsheets/d/1sEQHpSKyHx9w2F_Xx3lm56SU1p-8eI81OYU5TYvQFvw/edit#gid=1520352505)

Can you check if it’s what you want? Thank you.

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [July 27, 2020, 2:56am UTC](https://community.glideapps.com/t/reading-parts-of-string-with-20-numbers/12989/16 "2020-07-27T02:56:18Z")

</div>

You can use the methods I listed here ot copy down the formulas, but only use it when arrayformula can’t work for your case.

> [@Tutorial: Arrayformula in Google Sheets, good practices & how to overcome Arrayformula restrictions with scripts](https://community.glideapps.com/t/tutorial-arrayformula-in-google-sheets-good-practices-how-to-overcome-arrayformula-restrictions-with-scripts/9727):
>
> Hi, Today I will show you the script that can make copying formulas down work, when it does not work with arrayformula. But first, let’s have some introductions about arrayformula, for those who has not used this before in Google Sheets, some equivalents in Glide and some good practices while using it. I hope it can help you in building your Glide apps as well as applying it in your normal day job. 
> 
> > **1/ Definition**
> >
> > Arrayformula is defined as “a range, mathematical expression using one cell range …
