Re: Trim() isn't stipping tab characters off my data in vbscript



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:

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

You could use a RegExp

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), ",")



.



Relevant Pages

  • Re: Trim() isnt stipping tab characters off my data in vbscript
    ... I used the replacecommand and it works great. ... The data file looks like this: ... The script code reads the input file, ... If I delete the tabs (which makes the ...
    (microsoft.public.scripting.vbscript)
  • Assistance needed with script.......
    ... have a somewhat simple script, ... I would like to parse from the data file, such as Front Director Paths, ... Device Emulation Type: FBA ... Device Defined Label Type: N/A ...
    (perl.beginners)
  • Re: OT: Umra posting statistics for May 2008
    ... rather than adding tabs (which can go all over the place if ... horror when I clicked on the "show formatting" button. ... language Jo's script is written in but something like C or Perl's ... always welcome :-) I'm just using Agent, ...
    (uk.media.radio.archers)
  • Re: Assistance needed with script.......
    ... this is the hoh structure ... >> script and the file that I am reading to gather the data. ... >> Device Capacity ... >> I would like to parse from the data file, such as Front Director Paths, ...
    (perl.beginners)
  • Re: Separation and Security
    ... Most account management processes can be handled by script commands. ... open the data file then go Define Accts.. ... This is a bit of a security loop hole since anyone with a password can ...
    (comp.databases.filemaker)