Hur gör jag för att lägga till "us" efter varje ord en en textbox? Lägga till: Koden lägger bara till us i det sista ordet inte alla, vilket jag vill. Här ett exempel som fungerar i vb6 eller senare.lägga till "us"
Jag vill också att man ska kunna ta bort "us" om det finns.
/HjortenSv: lägga till
if right$(text1.text,2)<>"us" then
text1.text=text1.text & "us"
end if
Ta bort:
if right$(text1.text,2)="us" then
text1.text=left$(text1.text,len(text1.text)-2)
end if
/johan/Sv: lägga till
Hur gör jag?
/HjortenSv: lägga till
Gör också en alfanumerisk test som kontrolerar att "orden" innehåller bokstäver.
Private Function MakeUSString(Text As String) As String
Dim Words() As String
Dim Index As Integer
Dim Word As String
Words = Split(Text, " ")
For Index = LBound(Words) To UBound(Words)
Word = Words(Index)
If LCase$(Word) <> UCase$(Word) Then
Words(Index) = Word + "us"
End If
Next
MakeUSString = Join(Words)
End Function
Private Function CleanUSString(Text As String) As String
Dim Words() As String
Dim Index As Integer
Dim Word As String
Words = Split(Text, " ")
For Index = LBound(Words) To UBound(Words)
Word = Words(Index)
If Right$(Word, 2) = "us" Then
Words(Index) = Left(Word, Len(Word) - 2)
End If
Next
CleanUSString = Join(Words)
End Function