Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Remove characters in a string

Reply
 
Old 07-07-2009   #1 (permalink)
Gavaskar


 
 

Remove characters in a string

Hello

I've got a string ->ScriptName = wscript.Scriptfullname and the actually
path is c:\testfolder\myprogram\script.vbs

I'm wanting to remove the script.vbs so I only have c:\testfolder\myprogram\
so I'm removing the last 10 characters or up to the \

How do I do that?



My System SpecsSystem Spec
Old 07-07-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: Remove characters in a string


"Gavaskar" <nospam@xxxxxx> wrote in message
news:OKp5aQ0$JHA.3432@xxxxxx
Quote:

> Hello
>
> I've got a string ->ScriptName = wscript.Scriptfullname and the actually
> path is c:\testfolder\myprogram\script.vbs
>
> I'm wanting to remove the script.vbs so I only have
> c:\testfolder\myprogram\ so I'm removing the last 10 characters or up to
> the \
>
> How do I do that?
>
You can do it like so:
1. Use the "InStrRev" function to determine the position of the right-most
backslash.
2. Use the "left" function to extract the leftmost x characters.
If unsure how to use these functions, check the examples in the helpfile
script56.chm, downloadable from the Microsoft site.


My System SpecsSystem Spec
Old 07-07-2009   #3 (permalink)
T Lavedas


 
 

Re: Remove characters in a string

On Jul 7, 4:47*pm, "Gavaskar" <nos...@xxxxxx> wrote:
Quote:

> Hello
>
> I've got a string *->ScriptName = wscript.Scriptfullname and the actually
> path is c:\testfolder\myprogram\script.vbs
>
> I'm wanting to remove the script.vbs so I only have c:\testfolder\myprogram\
> so I'm removing the last 10 characters or up to the \
>
> How do I do that?
You can use the trick of adding "\.." to reference the path, without
actually altering the string, as follows ...

sVirtualPath = ScriptName & "\.."

or use the FSO GetParentFolderName to strip off the script's name ...

sPath = CreateObject("Scripting.FileSystemObject")_
.GetParentFolderName(ScriptName) & "\"

or maybe this little trick ...

sPath = replace(wsh.ScriptFullName, wsh.ScriptName, "")

The first one is functional, but not acceptable for displaying the
information. The second is the 'official' way to do it. While the
third approach is the one I prefer.

Tom Lavedas
************
My System SpecsSystem Spec
Old 07-07-2009   #4 (permalink)
Gavaskar


 
 

Re: Remove characters in a string

Thanks, got it.

"Gavaskar" <nospam@xxxxxx> wrote in message
news:OKp5aQ0$JHA.3432@xxxxxx
Quote:

> Hello
>
> I've got a string ->ScriptName = wscript.Scriptfullname and the actually
> path is c:\testfolder\myprogram\script.vbs
>
> I'm wanting to remove the script.vbs so I only have
> c:\testfolder\myprogram\ so I'm removing the last 10 characters or up to
> the \
>
> How do I do that?
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Select first 16 characters in a string PowerShell
How to Randomize characters in a string VB Script
Replacing Multiple Characters In A String PowerShell
Capture a string of characters and use as filename. PowerShell
Removing characters from a string PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46