Start a new topic

Substring function

Moderators closed for further comments a thread which demonstrated a substring function for enhanced nextions, but did not show how it is done. 


Here is how I did a substring for 3-character month abbreviations:

[code]

wepo "JanFebMarAprMayJunJulAugSepOctNovDec",0 

sys0=rtc1-1*3

repo t10.txt,sys0 

[/code]


This works because the length of t10.txt is 3, and sys0 (rtc month -1 times 3) says where to start.


If you make the receiver of the repo command of length 1, and then iterate in a loop for the number of characters you want to substring out, and append each character to the string where you want the result to be, then you should be able to perform a substring of any desired length.


This does not work in the simulator (when last tried), because wepo doesn't work.

It does work on a real enhanced nextion.



Not bad for a fixed known length, but variable length at runtime fails.

With such a case of month names, wepo/repo chews up more processing time needlessly

better to create an array of 12 strings and just access by rtc1 as index of

So in a substring function, like I demonstrated was possible, one must be able to have the user state where the start is and process a user requested length at runtime.  These are unknown lengths and your t10 is fixed at 3, so how do you purpose to provide the needed flexibility

for the record, I bet it is much better for your learning and understanding, when you find the solution by yourself. Copy and Paste is not the way we support in general ...

Threads will be locked, when users start to became rude, impertinent or insulting in any case ...

It is up to the user to accept and tolerate this, and it is up to us to lock a thread when users don't accept the red line ... to keep the forum clean and informative for others, there is a 0% tolerance ...


Anyway, you got an idea ... well done ...



For the record, I saw nothing in that other closed thread which was "rude, impertinent or insulting".


"impertinent"--that's an interesting word.


It's not clear that what I wrote was actually read--I didn't say it was a solution, I said it was a suggestion of how a solution might work--by iterating through a string using repo to move characters to a variable of length 1, and appending those characters to the desired result.


Here is code which will do that.


cov t2.txt,sys0,0

cov t4.txt,sys2,0

sys1=sys0+sys2-1

wepo t0.txt,0

t5.txt=""

for(sys2=sys0;sys2<=sys1;sys2++)

{

  repo va0.txt,sys2

  t5.txt=t5.txt+va0.txt

}

Here is a screen shot:

image


And attached is the HMI file.


The "FROM" and "LEN" boxes link to a numeric keyboard.

The main text box links to a qwerty keyboard so someone can enter new text.


This code is not provided with safeguards against incorrect "FROM" or "LEN" values being entered--it is just an example. If people don't like using eeprom this way, they are free to not use it or to show their superior code (or not as they wish).


HMI

It wasn't your fault the substring thread was closed.

Inappropriate responses can be deleted.

No sense leaving inappropriate non-professional remarks when not needed.


Coercing for code is not tolerated on the board.  If users desire to attach code they are welcome.

But when the user says no, it is suppose to be respectfully honored.

Such was not the case the day the thread was locked.


I post many pieces of code, including full techniques and source.

This was my right to not give the code for substring but just the TFT for peer review

proof that it was indeed accomplished.


BTW I should say congrats to you actually working through this to create your substring function.

The substring is a major building block that can enhance your programs. 


So indeed Congrats and happy coding.

to claim a forum contribution as "useless" in the name of all users is

    - rude
    - contraproductive
    - even deterrent for other contributors

and that's exactly what we don't like ... everybody can be critical to any contribution, if his opinion is also technically founded ... emotional statements should be avoided.

Back to the thread, as told, your solution works and is good ... CONGRATULATIONS ...

 

You should actually feel pride in what you have accomplished.


You are the first in 2 1/2 months since I announced it to post

  a) an attempt at working towards a substring

  b) an actual working methodology for producing a substring

I think you're the first that did something other than merely ask for the code.

(Gerry and I excluded).


Now with a substring you could actually create interpreting inside Nextion interpreter.

So feel pretty freakin proud ... and again Congrats.


just my words ... couldn't say it better ...

 

Login or Signup to post a comment