Hi Margret and Roft,
I have 2 function about manage string in VB 6.0 ,I need use in B4A . I cann't. Please help me to correct them I tried them ,have always error. this my code:
Sub StrCutTokenStrAll(Passedstring As String,TokenStr As String) As String
'This function to check 2 string be same data (i.e. "Book1" = "Book 1" )
Do Until InStr(Passedstring, TokenStr) = 0
Passedstring = Left(Passedstring, InStr(Passedstring, TokenStr) - 1) & Mid(Passedstring, InStr(Passedstring, TokenStr) + 1, Len(Passedstring) - InStr(Passedstring, TokenStr))
Loop
Return Passedstring
End Sub
Sub GetWord( StrVar As String,token As String, Nth As Int) As String
' This function returns the Nth token in a string
' Ex. msgbox GetWord("This is a test.", " ", 2) return "is"
Dim i As Int
Dim p As Int
Dim R As Int
Dim TargetStr As String
'*****************
TargetStr = " "
For i = 1 To Len(StrVar)
If Mid(StrVar, i, 1) = " " Then
If Mid(StrVar, i - 1, 1) <> " " Then
TargetStr = TargetStr + Mid(StrVar, i, 1)
End If
Else
TargetStr = TargetStr + Mid(StrVar, i, 1)
End If
Next
StrVar = Trim(TargetStr)
If Nth < 1 Then
Return ""
Exit
End If
R = 0
For i = 1 To Nth
p = R
R = InStr( p + 1,StrVar,token)
If R = 0 Then
If i = Nth Then
Return Mid(StrVar, p + 1, Len(StrVar) - p)
Else
Return ""
End If
Exit
End If
Next
Return Mid(StrVar, p + 1, R - p - 1)
End Sub
Hello All,
*** Just Added These New Functions: April 6th, 2012 - 10.00pm
Attached to Bottom of This Post: Version 1.2
Corrected for B4A version 1.9
AsciiCodes(), SearchDate(), DateNew(), DateNOD(), Date(), Split(), InStr(), MB(), ValidDate()
AsciiCodes - 'Displays an dialog showing all the Ascii Codes
Date - 'returns the current system date
SearchDate("04/06/2012", "04/14/2012", 30) - 'true means the dates passed are within (x) days of each other, pass x as 3rd parameter
DateNew("02/12/2012", 90) - 'returns a new date 90 days later, 2nd parameter can be + or - number
DateNOD("04/06/2012", "12/12/2011") - 'show the days passed between dates passed
ValidDate("13/12/2012") - 'returns true if you pass a valid date
InStr("Where is me at", "me") - 'shows the location of 2nd parameter in string (RBsoft)
Split("Here is a test string to take apart", " ") - 'returns the string split into List elements at each occurance of the 2nd parameter (RBsoft)
MB("My Text Here") - 'same as MsgBox() but only the one parameter is needed
*** Just Added These Three New Functions: August 25th, 2011 - 1.10pm
s.Proper() – Example: converts “jerry smith” to “Jerry Smith” or "ms. betty sue smith" to "Ms. Betty Sue Smith"
s.Lower()
s.Upper()
*** Just Added These Three New Functions: July 28th, 2011 - 12.27am
s.Space()
s.RndChrGen() - Generate random characters to fill Edit.Text, etc.
s.Exist()
*** Just Added These Two New Functions: July 24th, 2011 - 2.27am
s.Empty()
s.iif() - (Immediate If - very useful)
Example: MyVar = s.iif(File.ExternalWritable, File.DirRootExternal, File.DirInternal)
I have now been writing in B4A for just over three weeks. Each day I learn something new and how powerful it is! But, at first I was lost and did not know how flexable it is but was still missing some string functions I used all the time in VB and others like Visual Fox. I have put together a sample of some UDFs I wrote and wanted to share them as so many others here have done! I hope it is useful for someone. The new functions are listed below:
s.At()
s.Left()
s.Len()
s.Ltrim()
s.Mid()
s.Right()
s.Rtrim()
s.Stuff()
s.Trim()
s.Val()
Thanks,
Margret