MSFN Forum: VBS substring - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

VBS substring Rate Topic: -----

#1 User is offline   iceangel89 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 453
  • Joined: 10-February 07
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 28 February 2008 - 03:18 AM

how do i remove characters like at the end with VBS? i am trying to get the string of the filename without the extension


#2 User is offline   IcemanND 

  • MSFN Junkie
  • Group: Super Moderator
  • Posts: 3,239
  • Joined: 24-September 03
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 28 February 2008 - 08:02 AM

Right(string,y) function to get the right side of string to len y
Left(string,y) to get the left side of string for len y
Mid(string, x, [len y]) to get substring from the point x to len y, if y is omitted go to end of string.

#3 User is offline   iceangel89 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 453
  • Joined: 10-February 07
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 28 February 2008 - 08:59 AM

oh ya thanks, didn't think abt this, usually in many programming languages there is a substring function lol

#4 User is offline   Scr1ptW1zard 

  • Junior
  • Pip
  • Group: Members
  • Posts: 56
  • Joined: 05-July 07

Posted 28 February 2008 - 09:09 AM

You may want to look at using the FileSystem Object for your purpose here.

You can see an example here:
http://www.devguru.com/technologies/vbscri...etbasename.html

#5 User is offline   gunsmokingman 

  • MSFN Addict
  • Group: Super Moderator
  • Posts: 1,991
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 28 February 2008 - 09:12 AM

You could also use the Split method or Split and Replace methods
Example
You have this path
C:\SomeFolder\Folder\Name.Ext
Example Split

Quote

Dim F1, F2, F3
F1 = Split("C:\SomeFolder\Folder\Name.Ext","\")
 For Each F2 In F1
  F3 = F2
 Next 
 F1 = Split(F3,".")
 WScript.Echo F1(0) & vbCrLf & F1(1)


Example Split And Replace

Quote

Dim F1, F2, F3
F1 = Split("C:\SomeFolder\Folder\Name.Ext","\")
 For Each F2 In F1
  F3 = Replace(F2,".Ext","")
 Next
 WScript.Echo F3


Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy