Removing Char of text

Hi All,

I have a data :

g="20:15:0" d="20:5:07" b="1:10:01"
I want to remove all char after ‘:’ sign, basically I want to convert the date in text into,

g="20:15" d="20:5" b="1:10"
I ever tried using nthfield command, but it won’t remove the last ‘:’ sign.

any help ?

thanks
Arief

Kem Tekinay produced this reverse Instr function, which will tell you the position of the LAST : character

When you know that, you take the LEFT( YOURSTRING, POSITIONOFLAST:MINUSONE)

[code]Function InStrRev_MTC(Extends src As String, start As Integer = 0, find As String) As Integer
#pragma BackgroundTasks False
#pragma BoundsChecking False
#pragma NilObjectChecking False

dim pos as integer
dim curPos as integer = 0
if start > 0 then src = src.Left( start )

do
curPos = src.InStr( curPos + 1, find )
if curPos = 0 then
exit
else
pos = curPos
end if
loop

return pos
End Function[/code]

or

dim v() as string = split(src,":")
v.remove(v.ubound)
src=join(v,":")

Or if you want a solution that’s slower (but smaller) than Dave’s try this:

Dim v As String = nthField(src, ":", 1) + ":" + nthField(src, ":", 2)

Thanks,

all of the solution were working nicely.

Regards,
Arief

Just to keep this complete, here is the regular expression to do it:

dim rx as new RegEx
rx.SearchPattern = "^(.*):[^:]*$"
rx.ReplacementPattern = "$1"
rx.ReplaceAllMatches = true

s = rx.Replace( s )

Um… no solution using declares?

Watch this space. Theres bound to be a plugin… :wink: