Search code examples
vb.netstring-formatting

how to format a string result consisting of 10 heats in total with 0 and the desired value


I have to insert the results of a query into a string of ten characters (numbers). The values must all be 0 and I need to replace only the last characters with those of the query cells.

My code:

Dim idClienteCosarConsorziati As New DataSet
idClienteCosarConsorziati = DB_SQL.OpenDataset("SELECT Anagrafica.ID_cliente FROM Anagrafica WHERE (((Anagrafica.ID_gruppo) Is Null) AND ((Anagrafica.ID_padre_consorzio)=13584))", "Anagrafica.ID_cliente")

Try
    Dim contenitore As DataTable = idClienteCosarConsorziati.Tables(0)
    For Each row As DataRow In contenitore.Rows
        For Each cells As String In row.ItemArray
            Dim stringtoserach As String = "E:\PDF_Fatture\" + Format(cells, "0000000000")
        Next
    Next
Catch ex As Exception
    MessageBox.Show(ex.Message)
End Try

I try with Format(cells, "0000000000") but the result does not have the 0s


Solution

  • String already has a function PadLeft

    cells.PadLeft(10, '0')