Start a new topic

No way!!! I have made a Substring function!! Ha!!

Okay Okay


It only works on Enhanced Nextion Models but it works.


t0.txt = "the quick brown fox jumps over the lazy dog"


I can ask it starts at 5, ask for a length to 11, issue a click

- returns "quick brown" to my Text Component/ String Variable


I can ask it starts at 17, ask for a length to 9, issue a click

- returns "fox jumps" to my Text Component/ String Variable


Oh, this is going to make my programs so much better ...

   ... sorry no other code - just that it CAN BE DONE.


This of course will mean that CHR(x) is possible

or to pull a character from string index 12 s[12], is also possible.


Because of all the overhead, it will not be very effective in high speed applications

 - but where done is better than not being done - it will rock.


Proof of the Concept:

Nextion Enhanced 3.5" model, Nextion Editor version 0.40

TFT file: don't bother with TFT file if this version becomes too old.


// Set the string you want to pull the substring from

subtext.txt="No way!!! I have made a Substring function!! Ha!!"

// Set the start position and the number of characters desired

substart.val=25

sublen.val=20

// either send these two clicks across the serial or tap blue box

click getsub,1

click getsub,0


This will display on the topline of text you want to pull from

And on the second line, the substring value after pulled

tft
(139 KB)

Proof of the Concept:

Nextion Enhanced 3.5" model, Nextion Editor version 0.41

TFT file: don't bother with TFT file if this version becomes too old.


Demonstration of using substart.val, sublen.val  above to yield

 - subleft, subright.


Added: a continuous scrolling text (right to left)

 - text is such that the text   tail head   is fully circular.


Next is a multi-text continuous scroll

 - where text1 is followed by text2 ... by textN and followed by text1


tft
(151 KB)

Photo showing left, mid, right - single line continuous scrolling

and a Font Dump to showcase char by number --> char


VGQ3X4ruo_RgjI0VHBkMu23yoyLTalu_rQ.jpg


Hi Patrick,

very impressive what you achieved here, but for the complexity of it it will be useless for most applications.

I plead for a minimal feature like

t6.txt=t2.txt[3]

to extract a single char from a text value. The firmware seems to be written in C/C++, so the implementation of it should not be too difficult (just scribbled down):
unsigned char getSingleChar(const char *txtvar, uint8_t index)
{
   if(!index || index>strlen(txtvar)) return INDEX_ERROR;
   return txtvar[index-1];
}

With that, you may do substringing as well, if you need it. The keyboard feature would be greatly improved with it, as you can specify the letter, caps and number key values in  just three strings:


_letter.txt="qwertzuiopasdfghjklyxcvbnm.,-"
_caps.txt="QWERTZUIOPASDFGHJKLYXCVBNM:;_"
_number.txt="1234567890!$%&/()=?+*#'<>|[]"
_current.txt=_letter.txt // in case of small letters being active

b28.txt=_current.txt[16] // always true regardless of the currently active set

 

You know what I mean?

 

Yeah Michael,

I agree 100% that this hacking a substring is not cycle friendly and not a base to be used in any normal application, it may be simply too slow.

 

  " I plead for a minimal feature like t6.txt=t2.txt[3] "


I agree that the firmware needs to provide for a substring for it to be useful for users.


BTW using mid as above, t2.txt[3] is already doable since a with of start 3 and length 1

sets, also doable, all chars within the set need be sequential however,

with the above, there is no such calling convention as you have in C


The above is massive hacking, and not the neat clean hack but more like dull axe kind of hacking,

with each part interpreted by firmware, extra IO delays, slowness is more compounded.


Now, as far as declaring keyboards in three statements, I would have to be weary.

Keys for all three sets would need be the same,  _current.txt[6] .... is possible as key #6

   - but this char based method only works neatly in English iso-8859-1, less so in other isos

   - each key pressed then must use more cycles to loop through for its index.

Sometimes it is better to spend the cycles in initialization and have the speed later.

  


Can You give us a HMI file for substr2 and substr4, please.

Best regards, B. Miljkovic

 

I guess, the HMI is not available for public, otherwise Patrick already would have post it instead of the TFT ... :-)

 

... and what for is TFT file - totaly useless for us users. I bought this display to do some usefull things, not to playing games. :(

 

maybe a TFT is useless for you, but many other users out take such a TFT to get some ideas about what can be done ... :-)


    - use a TFT to get some ideas, to see it can be done ...

    - it is not forbidden, that you do such things by yourself ... after you saw it can be done ...

    - try things by yourself first ... instead of just copy and paste and beg others for sources ...

    - that's what I would call "do some usefull things"...



What? Is there something wrong with creating games?

Do you not like my Games I posted?  They show techniques to problem solving.


The TFT files are for peer review, proof that I accomplished what I claimed.


But I know I clearly stated in the thread header

   ... sorry no other code - just that it CAN BE DONE.