String Manipulation

cnicolapc

Active Member
Licensed User
Longtime User
Hi,
does anyone know how to convert a string that contains CRLF in a string of text without CRLF?
Thank You.
Nicola
 

cnicolapc

Active Member
Licensed User
Longtime User
Hi Rolf,
Thank you for sharing your example.
I tried pressing the button but the result is this go.
I think I'll go to sleep ... last night was 3:00 am.
Hopefully tomorrow will be a profitable day.
Bye Nicola
 

Attachments

  • shot_000057.jpg
    shot_000057.jpg
    9.2 KB · Views: 212
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Mabe I uploaded the wrong file. Here is a screenshot plus the project to it.

The last entry is the one where the CRLF is removed.

Rolf
 

Attachments

  • scrnshot.jpg
    scrnshot.jpg
    9.9 KB · Views: 185
  • listboxtest2.zip
    6.6 KB · Views: 177
Last edited:
Upvote 0

cnicolapc

Active Member
Licensed User
Longtime User
Hi, Rolf
my brain is melting.
B4X:
For i = 0 To Cursor1.RowCount - 1
        Cursor1.Position = i
      valore=Cursor1.GetString("Codice")
      valore2=Cursor1.getstring("Cosa")
      Valore3=Cursor1.getstring("Dove")
      If valore2.Length >=30 Then
      Valore2=valore2.SubString2(0,30)&"..."
      End If
      If valore3.Length >=39 Then
      Valore3=valore3.SubString2(0,39)&"..."
      End If
      Valore2 = Valore2.Replace(Chr(10)," ")
      Valore2 = Valore2.Replace(Chr(13)," ")
      
            ListaCose.AddTwoLines2(Valore2,Valore3,Valore)
            
            Next
   Cursor1.Close
   
End Sub

This is my code and this is the result. It may be that taken from a field CRLF SQL codes are different?
Thank You for patience
Nicola
 

Attachments

  • 1.jpg
    1.jpg
    8.5 KB · Views: 185
  • shot_000059.jpg
    shot_000059.jpg
    4.8 KB · Views: 186
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
You need to check if there are any other chars in the string, like chr(0) etc.

Rolf
 
Upvote 0

cnicolapc

Active Member
Licensed User
Longtime User
Hi Rolf,

I have yet to understand why, but I found that by using the replace before writing the record in the database, the problem is resolved.
As if I write the record without using the Replace command, and after reading the record does not resolve the problem.
I think that the record contains the string of unrecognized characters.
Now try to understand.
Today I will be there for work but tonight I will try to understand something (in the limit of my ability).
If anybody has any idea is welcome.
Thank you for support
Nicola
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
I have yet to understand why, but I found that by using the replace before writing the record in the database, the problem is resolved.
As if I write the record without using the Replace command, and after reading the record does not resolve the problem.
This sounds strange.
Where does the original text come from ?
What database do you use ?
What type is the database field ?
Does the original text already have these characters ?
If the original text has the special characters and you write it to the database and you read it back, it's normal that the characters remain.

Best regards.
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Would it be possible to upload your project? That would make it much easier to locate the problem.

Rolf
 
Upvote 0

cnicolapc

Active Member
Licensed User
Longtime User
Hi,
Klaus, Rolf
is a normal EditText multiline saved in a database SqlLite
the only thing I did, and press Enter after each word

I just added this routine to change the height of Edittext
The variable value2 is related to the field cosatxt.text

B4X:
ub SetCosaTextHeight
   CosaTxt.Height = Max(60dip, 30dip + su.MeasureMultilineTextHeight(CosaTxt, CosaTxt.Text))

   Labdove.top=CosaTXT.top + CosaTxt.Height
   DoveTxt.top=Cosatxt.Top + CosaTxt.Height + Labdove.height
   Labquando.Top=DoveTXT.top  + DoveTxt.Height
   QuandoTxt.Top=DoveTXT.top  + DoveTxt.Height
   BtnDate.Top=DoveTXT.top  + DoveTxt.Height+5dip
   LabCat.Top=Quandotxt.Top + Quandotxt.Height
   TestoCat.Top=Labcat.Top + Labcat.height
   Spnrname.Top=Labcat.Top+Labcat.height
   Newcat.top=Labcat.Top+Labcat.height+5dip
   LabNote.Top=Testocat.Top + testocat.Height
   Notetxt.Top=LabNote.Top + Labnote.height
   
End Sub

That's the part about saving
I converted the variable Vcosa derived from the Edittext cosaTxt.text and so would work.

B4X:
Sub Salva_Click
Salvato = False 
NewCatTxt=Testocat.text
If NewcatTxt="" AND Dovetxt.Text="" AND CosaTxt.Text="" Then
StartActivity("Lista")
Else
If NewcatTxt="" OR Dovetxt.Text="" OR  CosaTxt.Text="" Then
ControllaImmissioni
Else

Try

Vcosa=CosaTxt.Text.Replace("'","''")
VcosaInizio=Vcosa.ToUpperCase.SubString2(0,1)
VcosaFine=Vcosa.SubString(1)
Vcosa=Vcosainizio&Vcosafine
Vcosa=Vcosa.Replace(Chr(13), " ")
Vcosa=Vcosa.Replace(Chr(10), " ")
Vquando=QuandoTxt.Text.Replace("'","''")
Vdove=DoveTxt.text.Replace("'","''")
SpinIndex=spnrname.SelectedIndex
NewCatTxt = TestoCat.Text 'spnrName.GetItem(SpinIndex)
Vcategorie= NewCatTXT
Vnote=NoteTxt.text.Replace("'","''")

If Salva.text= "Aggiorna" Then 
Sql1.ExecNonQuery("UPDATE Articoli SET Cosa= '" & Vcosa & "', Dove= '" & Vdove & "',Quando='" & Vquando & "',Categoria='" & Vcategorie & "',Note= '" & Vnote & "'where Codice= '" & main.CodiceGlo & "' ") 

Else
   Sql1.ExecNonQuery("INSERT INTO Articoli VALUES(NUll,'" & Vcosa & "','" & Vdove & "','" & Vquando & "','" & Vcategorie & "','" & Vnote & "')") 
ToastMessageShow(Main.Dlg7,False)'"Salvataggio completato"
Salvato=True
End If
Catch
Errore= LastException.message
If Errore.Contains ("is not unique")  Then
Ret=Msgbox2(Main.Dlg11,Main.dlg4,"",main.dlg12,main.dlg13,Null)'"Una voce con questo nome esiste già nell'archivio",Attenzione,Correggo,Elimino
Select ret 
Case -3 
cosatxt.RequestFocus
cosatxt.SelectAll
Return True
Case -2
CosaTxt.Text=""
   DoveTxt.Text=""
   NoteTxt.Text=""
   TestoCat.Text=""
   CosaTxt.RequestFocus
   End Select

End If

End Try
'Imposta data corrente
    Dim t As Long
      t = DateTime.Now
    DateTime.DateFormat = "dd/MM/yyyy"'Formatta la data
    Dim s As String
    s = DateTime.Date(t)
'************************************
CosaTxt.Text=""
   DoveTxt.Text=""
   Quandotxt.text=s
   NoteTxt.Text=""
   TestoCat.Text=""
   CosaTxt.RequestFocus
End If
End If
End Sub
Thank You
Nicola
 
Last edited:
Upvote 0

cnicolapc

Active Member
Licensed User
Longtime User
Hi,
what makes me most angry is the fact that I msgbox returns the correct message.
B4X:
Sub LoadLista
ListaCose.Clear
listacose.BringToFront
If main.ListaOpzioni=2 Then
      Cursor1=Sql1.ExecQuery2("SELECT Codice,Cosa,Dove,Quando,Categoria,Note FROM articoli where cosa like ? ORDER BY cosa", Array As String(main.Cercacosa))
      Else
   If main.ListaOpzioni=3 Then
      Cursor1=Sql1.ExecQuery2("SELECT Codice,Cosa,Dove,Quando,Categoria,Note FROM articoli where Dove like ? ORDER BY cosa", Array As String(main.CercaDove))
   Else
      If main.ListaOpzioni=4 Then
      Cursor1=Sql1.ExecQuery2("SELECT Codice,Cosa,Dove,Quando,Categoria,Note FROM articoli where categoria like ? ORDER BY cosa", Array As String(main.Cercacategorie))
   Else
   Cursor1 = SQL1.ExecQuery("SELECT Codice,Cosa,Dove,Quando,Categoria,Note FROM Articoli ORDER BY Cosa")
   End If
   End If
   End If
    For i = 0 To Cursor1.RowCount - 1
        Cursor1.Position = i
      valore=Cursor1.GetString("Codice")
      valore2=Cursor1.getstring("Cosa")
      Valore3=Cursor1.getstring("Dove")
      If valore2.Length >=30 Then
      Valore2=valore2.SubString2(0,30)&"..."
      End If
      If valore3.Length >=39 Then
      Valore3=valore3.SubString2(0,39)&"..."
      End If
      Msgbox(Valore2,"Normale")
      Valore2=Valore2.Replace(Chr(13), " ")
      Msgbox(Valore2,"Con Chr 13")
        Valore2=Valore2.Replace(Chr(10), " ")
      Msgbox(Valore2,"Con Chr 10")'**************** CORRECT LINE ****************
         ListaCose.AddTwoLines2(Valore2,Valore3,Valore)
            
            Next
   Cursor1.Close
   
End Sub
 

Attachments

  • shot_000067.jpg
    shot_000067.jpg
    6.6 KB · Views: 180
  • shot_000069.jpg
    shot_000069.jpg
    6.7 KB · Views: 192
  • shot_000068.jpg
    shot_000068.jpg
    6.4 KB · Views: 194
Upvote 0

cnicolapc

Active Member
Licensed User
Longtime User
Hi,

I found the error!!!, I put the same code of Sub LoadLista in Activity_Resume without the command Valore2.Replace.
Thank you for your help, however, that helped me to learn many things including the review more carefully written code.
And I apologize for the time that I did lose.
I hope one day I too can give my contribution
Ps. (sorry for my bad English always)
:BangHead:

Nicola
 
Last edited:
Upvote 0
Top