?
Solved

Modify text using vbscript

Posted on 2013-05-13
7
Medium Priority
?
266 Views
Last Modified: 2013-05-16
Hello,
I have a dilemma,

In VBS, I have a variable that reads a text input:

strObj = "Text/Text2/Text3"

I need to edit strObj so it will say only "Text/Text2" (basically discard everything after the 2nd "/" including)

Any advise?
0
Comment
Question by:johnnyjonathan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 800 total points
ID: 39163240
Try this:
Option Explicit

Dim strObj, iPos

strObj = "Text/Text2/Text3"

iPos = InStr(strObj, "/")
If iPos > 0 Then
	iPos = InStr(iPos + 1, strObj, "/")
	If iPos > 0 Then
		strObj = Left(strObj, iPos - 1)
	End If
End If

MsgBox strObj

Open in new window

0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 800 total points
ID: 39163259
Hi, I just wrote this little function, which should work for you.  It returns the position of the specified instance of a character.

Regards,

Rob,

strObj =   "Text/Text2/Text3"

intChr = FindChrPos(strObj, "/", 2)

WScript.Echo intChr
WScript.echo Left(strObj, intChr - 1)

Function FindChrPos(strTheString, strTheChr, intInstance)
	intStart = 1
	For intNum = 1 To intInstance
		intFound = InStr(intStart, strTheString, strTheChr, vbTextCompare)
		intStart = intFound + 1
		If intStart > Len(strTheString) Then Exit For
	Next
	If intNum < intInstance Then intFound = 0
	FindChrPos = intFound
End Function

Open in new window

0
 
LVL 56

Assisted Solution

by:Bill Prew
Bill Prew earned 200 total points
ID: 39163344
Here's a fairly simple approach.

arrTemp = Split(strObj, "/")
strObj = arrTemp(0) & "/" & arrTemp(1)

Open in new window

~bp
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 53

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 200 total points
ID: 39163348
function cut(x)
   arr=split(x,"/")
   cut=arr(0)&"/"&arr(1)
end function


strObj = "Text/Text2/Text3"
response.write cut(strObj)

Open in new window

0
 

Author Closing Comment

by:johnnyjonathan
ID: 39172019
Thanks all! worked like a charm
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 39172518
Not griping, you are certainly free to select any working solution as you see fit.  Just want to understand if I missed anything, what made http:#a39163344 such an inferior solution for you, seems pretty compact and effective?  Or was it just because it wasn't first on the scene?

~bp
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39172600
I agree. I did the same thing as @billprew - we posted just about the same time.  The only difference is I made a function so you can call the function anywhere in the code multiple times with one line.

There are always many ways to the same visual outcome though.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question