Can any tell me (or have an example) of how to trim a string?

I would like to remove all /'s and :'s from the a now (date and time) value, e.g. 01/02/2005 12:22:33
0 Comments   [ + ] Show Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.


There's a find/replace vbscript . It does file manip. Not sure what you want to do with the date, but if you could output it to a file, do your manipulation then do your processing. I'm sure there's also a way to do the manip without writing to a file, just manipulate the variable.

' This script finds and replaces the CD ROM drive D: with the correct drive letter in the setup.var and
' student.var files (see constant EXT below) (see SubFolder)
' This allows the Borescope Training to run even where the drive letter is not D:
' Owen Gilmore - '

Option Explicit

'Define Object Variables
Dim FSys
Dim xFolder
Dim xFiles
Dim xFile
Dim tFile
Dim wshShell
'On Error Resume Next
Dim strComputer
Dim objWMIService
Dim colItems
Dim objFSO
Dim objShell
Dim strmsg
Dim u_CDDrv
Dim u_MedPath
Dim objItem

' Define Working Variables
Dim SubFolder
Dim FileText
'Define Constants
Const EXT = "var"
Const ForReading = 1
Const ForWriting = 2
Const TristateUseDefault = -2

'On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

For Each objItem in colItems

strmsg=strmsg&"Media Loaded: " & objItem.MediaLoaded&vbcrlf
strmsg=strmsg&"Drive: " & objItem.Drive&vbcrlf

If objItem.MediaLoaded = "True" and objFSO.FolderExists(objItem.Drive & u_MedPath) Then
u_CDDrv = objItem.Drive
End If

SubFolder = "C:\United\BORESCBT\VARIABLE"

'Verify that the script runs in console mode
If UCase(Right(WScript.FullName, Len(WScript.FullName)-InStrRev(WScript.FullName,"\"))) <> "CSCRIPT.EXE" Then
Set wshShell = WScript.CreateObject("WScript.Shell")
wshShell.Run "CSCRIPT.EXE " & WScript.ScriptFullName, 1, False
Set wshShell = Nothing
End If

'Set Objects
Set FSys = WScript.CreateObject("Scripting.FileSystemObject")
Set xFolder = FSys.GetFolder(SubFolder)
Set xFiles = xFolder.Files

WScript.Echo SubFolder
WScript.Echo "Directive to process " & xFiles.Count & " files."

'Parse Each file and perform replacements
For Each xFile in xFiles
if Right(lcase(xFile.Name), 3) = EXT Then

WScript.Echo " --> " & xFile.Name
WScript.Echo " Reading in contents"

Set tFile = xFile.OpenAsTextStream(ForReading, TristateUseDefault)
FileText = tFile.ReadAll

WScript.Echo " Performing Replacement"
FileText = REPLACE(FileText, "D:", u_CDDrv)

WScript.Echo " Saving new file"
Set tFile = xFile.OpenAsTextStream(ForWriting, TristateUseDefault)
tFile.Write FileText

FileText = ""
WScript.Echo " --> " & xFile.Name & " NOT APPLICABLE"
End If


'Clean Environment and exit
On Error Resume Next

Set tFile = Nothing
Set xFolder = Nothing
Set xFiles = Nothing
Set xFile = Nothing
Set FSys = Nothing
Answered 02/01/2005 by: aogilmor
Ninth Degree Black Belt

Please log in to comment
Trim is used to remove spaces from the start or end of a string, I think Replace is the fuction you are looking for:
'Long Version:
TimeString = Now()
TimeString = Replace(TimeString,"/","") ' Replace all forward slashes with empty space
TimeString = Replace(TimeString,":","") ' Replace all colons with empty space

'Short Version:
TimeString = Replace(Replace(Now(),":",""),"/","")

You mention "Now" for time so I'm assuming VBScript, if this is not the language you are referring to, say what language you are using. For example in KiXtart, there is no built in replace funciton, but you can use Split and Join to do the same like this:
$TimeString = @TIME
$TimeString = Join (Split($TimeString,":"),"")
Answered 02/01/2005 by: bkelly
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity