Visual Basic - algoritmer - Strings
Field
Numeric string
Replace
| Private Function FS(F As Integer, S As String) As String Dim T As String T = Space(F) RSet T = S FS = T End Function |
| Private Function FN(F As Integer, N As Single) As String FN = FS(F, Format(N, "fixed")) End Function |
| i = 5 : snPrin = 2550,45 sAdd = FS(5, Str(i)) & FN(10, snPrin) |
123451234567890
5 2550,45
|
| Dim bin As String * 8, p As Integer bin = "00000000" p = 8 Do While num > 0 And p > 0 If num Mod 2 Then Mid$(bin, p) = "1" num = num \ 2 p = p - 1 Loop |
Function replace (text$, start%, length%, txt$) As String Dim L%, Tail% L% = Len(text$) + 1 Tail% = L% - start% If start% < 1 Then start% = 1 If start% > L% Then start% = L% If length% < 0 Then length% = 0 If length% > Tail% Then length% = Tail% replace = Left$(text$, start% - 1) & txt$ & Right$(text$, Tail% - length%) End Function 'Ex: label1 = replace(CStr(text1), Val(text2), Val(text3), CStr(text4)) |