/build/static/layout/Breadcrumb_cap_w.png

Trimming a string

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

Answers (2)

Posted by: aogilmor 19 years ago
9th Degree Black Belt
0
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 - ' aogilmore@sbcglobal.net

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")
u_MedPath = "\BORESCBT\DATABASE"

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
WScript.Quit
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
tFile.Close

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

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

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

Next


'Clean Environment and exit
On Error Resume Next

Set tFile = Nothing
Set xFolder = Nothing
Set xFiles = Nothing
Set xFile = Nothing
Set FSys = Nothing
Posted by: bkelly 19 years ago
Red Belt
0
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,":"),"")
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ