Is it possible to take part of a CSBuilder sequence and maintain the formatting?
Reason I ask is to speed up real time formatting of an SQL EditText. As it is if the text is altered
(say only one character) then the whole text needs to be reformatted. What I would like is for example this:
select field1 from table1
now if we alter this and make it:
select field1 from table2
then only one word needs to be reformatted, table2.
So, what I would like is keep the CSBuilder sequence up to table2 as a CSBuilder variable, reformat table2, so this will be a new variable, then join these 2.
I searched the forum and looked at the methods and properties of CSBuilder, but it doesn't look this is possible. Is this indeed the case or is there a way?
Got this all working now. It was tricky, but it speeds indeed the SQL formatting up a lot.
Not that it was slow, but possibly it could be a problem on slow phones (although this is
for now a personal app) or with large SQL's.
Thanks again for the tip.
Why would you say that. Look at this below example where I use substring2 and substring with csbuilder without the use of JavaObject lib and it works flawlessly. Are you meaning something else with your statement maybe.
B4X:
Dim cs As CSBuilder
Dim strvar As String ="FRANCE WON THE WORLD CUP IN 2018"
cs.initialize.Color(Colors.Red).Append(strvar.SubString2(0, 5)).Color(Colors.Blue).Append(strvar.SubString2(5, 8)) _
.Color(Colors.Green).Append(strvar.SubString(8)).PopAll
Dim cs1 As CSBuilder
Dim strvar As String =" INFORMATIX LOVES IT"
cs1.initialize.Color(Colors.Magenta).Append(strvar).PopAll
Dim cs3 As CSBuilder
cs3.Initialize.Append(cs).Append(cs1)
lbl.Text=cs3
Yes, but that will change my CSBuilder charsequence to a regular string. I need it to remain charsequence.
Unless I am overlooking something I think I will need the Java object.
This simple function does the job for me:
B4X:
Sub SubCharSequence2(oCS As CSBuilder, iBeginIndex As Int, iEndIndex As Int) As CSBuilder
Dim JObj As JavaObject
JObj = oCS
Return JObj.RunMethod ("subSequence", Array (iBeginIndex, iEndIndex))
End Sub
Thanks for confirming.
Done some further testing and not quite so sure now it is worth it to format only part of the SQL and keep charsequences that remain
unaltered. It does get complex (eg with SQL comments) and gain in time is not that much. Maybe a case of premature optimization, which
as you say is the source of all evil.