08. januar 2006 - 11:33Der er
10 kommentarer og 1 løsning
Bestemt længde på String
Hej
Jeg har en String, som SKAL indeholde 8 tegn. Hverken mere eller mindre. Altså f.eks. "00000000" Er det muligt at teste på antal tegn i en streng. Eller oprette den med et bestemt antal og hvis nogle tegn ikke bruges skrives der bare et 0.
arne_v : det her vil give fejl MsgBox pad8("1234567890")
ellers så prøv den her:
Private Sub Form_Load() MsgBox StringLength("", 8, "0") ' 00000000 MsgBox StringLength("123456", 8, "0") ' 00123456 MsgBox StringLength("1234567890", 8, "0") ' 12345678 End Sub
Public Function StringLength(strText As String, intLen As Integer, strChar As String) StringLength = Right$(String(intLen, strChar) & Left$(strText, intLen), intLen) End Function
Public Function StringLength(strText As String, intLen As Integer, strChar As String) As String StringLength = Right$(String(intLen, strChar) & Left$(strText, intLen), intLen) End Function
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.