Re: Trim() isn't stipping tab characters off my data in vbscript
- From: "ekkehard.horner" <ekkehard.horner@xxxxxxxx>
- Date: Wed, 09 Jan 2008 18:18:37 +0100
Barry schrieb:
I have a data on our server that houses data for mapping specific folders to specific users and/or groups in AD. The data file looks like this:You could use a RegExp
Group, Sales, G:, \\MSO-Server\Groups-Users\Sales
User, All_Users, H:, \\MSO-Server\Groups-Users\Personal_Folders\
Group, Acctng, J:, \\MSO-Server\Groups-Users\Public
Group, H_R, K:, \\MSO-Server\Groups-Users\Human_Resources
Group, Executive, L:, \\MSO-Server\Groups-Users\Executive
Group, All_Users, M:, \\MSO-Server\Groups-Users\Public
Group, NetAdmin, N:, \\MSO-Server\Groups-Users\NetAdm
Group, NetAdmin, O:, \\SBS-Server\C$
Group, NetAdmin, P:, \\SBS-Server\D$
(The blank spaces in the file are tabs for readability.)
The script code reads the input file, populates arrTxtArray(). The code segment below then parses it into discrete array fields to be used later in the script for mapping.
For i = LBound(arrTxtArray) To UBound(arrTxtArray)
newArray = Split (arrTxtArray(i), ",")
MapInfo(i, 0) = Trim(newArray(0)) ' User or Group
MapInfo(i, 1) = Trim(NewArray(1)) ' Group Name
MapInfo(i, 2) = Trim(newArray(2)) ' Drive Letter
MapInfo(i, 3) = Trim(newArray(3)) ' Path
WScript.Echo i+1 & ". - " & MapInfo(i, 0) & " - " & MapInfo(i, 1) &_ " - " & MapInfo(i, 2) & " - " & MapInfo(i, 3)
Next
The issue I'm having is that the Trim() command is not stripping the tab characters off the data as it is written into the MapInfo array. I can tell this from the wscript.echo command. If I delete the tabs (which makes the source file hard to read) the script works fine. What might I use instead of Trim() to accomplish my task? Thanks in advance. BH
Set s_reTrimWS = New RegExp
s_reTrimWS.Pattern = "^\s+|\s+$"
s_reTrimWS.Global = True
to remove all whitespace from a string sTxt:
sTxt = s_reTrimWS.Replace( sTxt, "" )
or (quick & dirty) use the VBScript Replace to do a more specialized
job:
For i = LBound(arrTxtArray) To UBound(arrTxtArray)
arrTxtArray(i) = Replace( arrTxtArray(i), vbTab, "" ) ' maybe " "
newArray = Split (arrTxtArray(i), ",")
.
- Follow-Ups:
- References:
- Prev by Date: Trim() isn't stipping tab characters off my data in vbscript
- Next by Date: Re: Trim() isn't stipping tab characters off my data in vbscript
- Previous by thread: Trim() isn't stipping tab characters off my data in vbscript
- Next by thread: Re: Trim() isn't stipping tab characters off my data in vbscript
- Index(es):
Relevant Pages
|