Assigning text to a variable. Problem, text contains tabs.
Moderators: Dorian (MJT support), JRL
-
- Newbie
- Posts: 14
- Joined: Fri May 13, 2005 8:51 am
Assigning text to a variable. Problem, text contains tabs.
I am copying text from an alarm system, writing it to a file, then assigning it to a variable, then entering it into a fault logging / ticketing system, the problem is that sometimes there is a Tab in the alarm text, this is being read as Press Tab and is shifting the focus and causing all sorts of problems, how can I replace the Tab with several spaces ?
I have tried the following :
stringreplace>INSTRUCTIONS, {there is a tab here} ,,INSTRUCTIONS
stringreplace>INSTRUCTIONS,Tab,,INSTRUCTIONS
Any ideas lads and lasses ?
Thanks.
I have tried the following :
stringreplace>INSTRUCTIONS, {there is a tab here} ,,INSTRUCTIONS
stringreplace>INSTRUCTIONS,Tab,,INSTRUCTIONS
Any ideas lads and lasses ?
Thanks.
-
- Newbie
- Posts: 14
- Joined: Fri May 13, 2005 8:51 am
Anyone ?
Is there anyone out there that can shed some light on the subject ? If my post was a little too complicated, then in summary, I want to character replace the invisible gap (tab) with something else, like 5 "space"s
-
- Newbie
- Posts: 14
- Joined: Fri May 13, 2005 8:51 am
Re: Anyone ?
- Whoops sorry.miles.williams wrote:Is there anyone out there that can shed some light on the subject ? If my post was a little too complicated, then in summary, I want to character replace the invisible gap (tab) with something else, like 5 "space"s
Something like this:
VBSTART
VBEND
VBEval>Replace("hello world",vbTab,""),new
e.g, if INSTRUCTIONS is your variable containing the string:
VBEVal>Replace("%INSTRUCTIONS%",vbTab,""),INSTRUCTIONS
VBSTART
VBEND
VBEval>Replace("hello world",vbTab,""),new
e.g, if INSTRUCTIONS is your variable containing the string:
VBEVal>Replace("%INSTRUCTIONS%",vbTab,""),INSTRUCTIONS
MJT Net Support
[email protected]
[email protected]
-
- Newbie
- Posts: 14
- Joined: Fri May 13, 2005 8:51 am
Thank you very much
I know nothing about VB yet, but just to clarify :
VBEVal>Replace("%INSTRUCTIONS%",vbTab,""),INSTRUCTIONS
This will replace a tab space (vbTab) with nothing (what is between the "") Is that right ? If this is the case could I replace it with " " ? (seven spaces, not showing up properly) Or would I need to have :
VBEVal>Replace("INSTRUCTIONS%",vbTab,"vbSpace*7"),INSTRUCTIONS
Thanks for the reply.
VBEVal>Replace("%INSTRUCTIONS%",vbTab,""),INSTRUCTIONS
This will replace a tab space (vbTab) with nothing (what is between the "") Is that right ? If this is the case could I replace it with " " ? (seven spaces, not showing up properly) Or would I need to have :
VBEVal>Replace("INSTRUCTIONS%",vbTab,"vbSpace*7"),INSTRUCTIONS
Thanks for the reply.
Hi,
Yes, my example replaces tab with nothing. You could replace it with seven spaces just by doing:
VBEVal>Replace("%INSTRUCTIONS%",vbTab," "),INSTRUCTIONS
Or:
VBEVal>Replace("%INSTRUCTIONS%",vbTab,Space(7)),INSTRUCTIONS
Yes, my example replaces tab with nothing. You could replace it with seven spaces just by doing:
VBEVal>Replace("%INSTRUCTIONS%",vbTab," "),INSTRUCTIONS
Or:
VBEVal>Replace("%INSTRUCTIONS%",vbTab,Space(7)),INSTRUCTIONS
Last edited by support on Thu Jun 09, 2005 6:33 am, edited 1 time in total.
MJT Net Support
[email protected]
[email protected]
-
- Newbie
- Posts: 14
- Joined: Fri May 13, 2005 8:51 am
hmm
That appears to have not worked, I'll supply the entire section of script that might make things clearer :
Previous to this I have copied and writeln'd text to a file c:\reminstruct.tmp...
Let>linenum=1
ReadLn>c:\reminstruct.tmp,%linenum%,line
Let>instructions=%line%%CR%
Let>linenum=%linenum%+1
label>start1
ReadLn>c:\reminstruct.tmp,%linenum%,line
If>%line%=##EOF##,end1
Let>INSTRUCTIONS=%INSTRUCTIONS%%line%%CR%
Let>linenum=%linenum%+1
Goto>start1
Label>end1
VBSTART
VBEND
VBEVal>Replace("%INSTRUCTIONS%",vbTab,Space(7)),INSTRUCTIONS
message>%instructions%
And the result from this is :
Microsoft VBScript compilation error :1033
Unterminatated string constant
Previous to this I have copied and writeln'd text to a file c:\reminstruct.tmp...
Let>linenum=1
ReadLn>c:\reminstruct.tmp,%linenum%,line
Let>instructions=%line%%CR%
Let>linenum=%linenum%+1
label>start1
ReadLn>c:\reminstruct.tmp,%linenum%,line
If>%line%=##EOF##,end1
Let>INSTRUCTIONS=%INSTRUCTIONS%%line%%CR%
Let>linenum=%linenum%+1
Goto>start1
Label>end1
VBSTART
VBEND
VBEVal>Replace("%INSTRUCTIONS%",vbTab,Space(7)),INSTRUCTIONS
message>%instructions%
And the result from this is :
Microsoft VBScript compilation error :1033
Unterminatated string constant
Something else in the string means VBScript doesn't like it. Here's another way to do it which uses the native StringReplace function:
//Put these two lines at start of script
VBSTART
VBEND
//This line gives us a native variable containing the tab character
VBEval>vbTab,msTab
//This line replaces occurences of msTab with seven spaces
StringReplace>INSTRUCTIONS,msTab, ,INSTRUCTIONS
//Put these two lines at start of script
VBSTART
VBEND
//This line gives us a native variable containing the tab character
VBEval>vbTab,msTab
//This line replaces occurences of msTab with seven spaces
StringReplace>INSTRUCTIONS,msTab, ,INSTRUCTIONS
MJT Net Support
[email protected]
[email protected]
could it be ?
I noticed in support's example that the VBreplace function had one%sign but Miles' had two. Syntax error?
Kris
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
-
- Newbie
- Posts: 14
- Joined: Fri May 13, 2005 8:51 am
SUCCESS !!!
Thank you guys I was pulling my hair out over that one, it works a treat ! Another problem solved.