问题
I'm trying to only show the date portion of a string field.
This is the format of the string: STARTED:/ 03/23/1983 TIME:/ 03:12
I need to remove "STARTED:/" and "TIME:/ 03:12" and only show the date portion of the string:03/23/1983
. What formula can I use to do that?
Thanks
回答1:
The Crystal Reports help file is your friend and should be your first stop for simple questions on built-in functions and data types.
In CR strings are just stored as character arrays so you can access them like arrays - by index. So in your case, if you will always have the same string format (that is, the same number of characters, leading zeroes, etc.) then you can do something like this:
local stringvar mystr := {table.your_string}; //mystr:="STARTED:/ 03/23/1983 TIME:/ 03:12"
mystr[11 to 20] //return "03/23/1983"
Alternatively, you could use the Mid() string function.
回答2:
I have used this formula to split the string of Full Name into "Last Name", rest of the string is concatenated as "First Name"
Dim string_array() As String
Dim i As Integer = 0
Dim ContactName As String = dt(0)("ContactName").ToString()
Dim contact_name As String
contact_name = String.Empty
If ContactName.Length = 0 Then
contact_name = String.Empty
Else
string_array = Split(ContactName, " ")
If string_array.Count > 1 Then
For i = 0 To string_array.Count - 2
If string_array(i) = String.Empty Then
Continue For
End If
contact_name = contact_name & " " & string_array(i)
Next
Else
contact_name = ContactName
End If
End If
来源:https://stackoverflow.com/questions/11703830/crystal-reports-split-string-formula