Ask a Question related to ASP Database, Design and Development.
-
Krechting #1
Get last part of a string
Hi All,
I'm trying to get the last part of a string.
In VB there's a function called lastinstr() who does the work.
But it doesn't seem to work in ASP.
The string I have is for example:
D:\Marco\ASIC2000\Images\Weapon\leo1schrägmit.jpg
Now I want to get rit of everything before the last "\" so that
leaves: leo1schrägmit.jpg
One of the problems I have is that I never know what the string
looks like so I always looked for the last instance of "\" and cut
eveything left of it.
In VB this code did it:
Function LastInStr(strSearched As String, strSought As String) As Integer
Dim intCurrVal As Integer
Dim intLastPosition As Integer
intCurrVal = InStr(strSearched, strSought)
Do Until intCurrVal = 0
intLastPosition = intCurrVal
intCurrVal = InStr(intLastPosition + 1, strSearched, strSought)
Loop
LastInStr = intLastPosition
End Function
Can I use this function in ASP, and Where do I put it.
Or is there something else I can do?
Regards
Marco
The NEtherlands
Krechting Guest
-
numeric part of a string
Can anyone tell me how can I get the numeric part of a string . for example I'm using this..Select substring('walnut 2224... -
Selecting part of a string
Hello all, How do I Select and put in a variable the url (www.domain.com) of the following string: javascript:openWin("www.domain.com") ... -
Parse part of string (mid string function ?)
Can someone tell me how to parse part of a string? I can use the following: <?php $text = $_SERVER; //$PHP_SELF //(document.url); echo $text;... -
RegExp that looks for a string and only replaced part of it...
I'm after a regular expression that looks through a string for a certain code, and then replaces part of that code with some markup: So look in... -
getting part of a string
Anyone have a sure way of grabbing just the file name from a string that looks like this: C:/Documents and Settings/Bobo the Bugbear/My... -
Foo Man Chew #2
Re: Get last part of a string
Why is this in the DB group?
Anyway, you can do this if you are already using FileSystemObject in the
page:
set fso = CreateObject("Scripting.FileSystemObject")
set fs = fso.GetFile("c:\boot.ini")
response.write fs.name
"Krechting" <m.krechting@chello.nl> wrote in message
news:a71c776d.0312281546.1d025920@posting.google.c om...> Hi All,
>
> I'm trying to get the last part of a string.
> In VB there's a function called lastinstr() who does the work.
> But it doesn't seem to work in ASP.
>
> The string I have is for example:
> D:\Marco\ASIC2000\Images\Weapon\leo1schrägmit.jpg
> Now I want to get rit of everything before the last "\" so that
> leaves: leo1schrägmit.jpg
>
> One of the problems I have is that I never know what the string
> looks like so I always looked for the last instance of "\" and cut
> eveything left of it.
>
> In VB this code did it:
>
> Function LastInStr(strSearched As String, strSought As String) As Integer
>
> Dim intCurrVal As Integer
> Dim intLastPosition As Integer
>
> intCurrVal = InStr(strSearched, strSought)
> Do Until intCurrVal = 0
> intLastPosition = intCurrVal
> intCurrVal = InStr(intLastPosition + 1, strSearched, strSought)
> Loop
> LastInStr = intLastPosition
>
> End Function
>
> Can I use this function in ASP, and Where do I put it.
> Or is there something else I can do?
>
> Regards
> Marco
> The NEtherlands
Foo Man Chew Guest
-
Paul #3
Re: Get last part of a string
use split() and take the last entry
e.g.
urlSplit = split("D:\Marco\ASIC2000\Images\Weapon\leo1schrägm it.jpg","\")
msgbox urlSplit(UBound(urlSplit))
regards
paul
"Krechting" <m.krechting@chello.nl> wrote in message
news:a71c776d.0312281546.1d025920@posting.google.c om...> Hi All,
>
> I'm trying to get the last part of a string.
> In VB there's a function called lastinstr() who does the work.
> But it doesn't seem to work in ASP.
>
> The string I have is for example:
> D:\Marco\ASIC2000\Images\Weapon\leo1schrägmit.jpg
> Now I want to get rit of everything before the last "\" so that
> leaves: leo1schrägmit.jpg
>
> One of the problems I have is that I never know what the string
> looks like so I always looked for the last instance of "\" and cut
> eveything left of it.
>
> In VB this code did it:
>
> Function LastInStr(strSearched As String, strSought As String) As Integer
>
> Dim intCurrVal As Integer
> Dim intLastPosition As Integer
>
> intCurrVal = InStr(strSearched, strSought)
> Do Until intCurrVal = 0
> intLastPosition = intCurrVal
> intCurrVal = InStr(intLastPosition + 1, strSearched, strSought)
> Loop
> LastInStr = intLastPosition
>
> End Function
>
> Can I use this function in ASP, and Where do I put it.
> Or is there something else I can do?
>
> Regards
> Marco
> The NEtherlands
Paul Guest
-
Krechting #4
Re: Get last part of a string
Hi Paul,
Tried what you told me but I only get a number returned.
Don't know how to get the last part of the string extracted.
txtImagePathAndFile.Value = "Images/Weapon/" &
UBound(Split(Recordset.Fields("txtImagePathAndFile "),"\"))
Returns: Images/Weapon/5
What I want is Images/Weapon/somepicture.jpg
Split and Ubound find the number of "/" in the string but i want the
text that is behind that last "/"
Regards
MArco
"Paul" <paul@nospam.com> wrote in message news:<e7mYDPazDHA.1364@TK2MSFTNGP10.phx.gbl>...> use split() and take the last entry
>
> e.g.
>
> urlSplit = split("D:\Marco\ASIC2000\Images\Weapon\leo1schrägm it.jpg","\")
> msgbox urlSplit(UBound(urlSplit))
>
> regards
> paul
>
> "Krechting" <m.krechting@chello.nl> wrote in message
> news:a71c776d.0312281546.1d025920@posting.google.c om...> > Hi All,
> >
> > I'm trying to get the last part of a string.
> > In VB there's a function called lastinstr() who does the work.
> > But it doesn't seem to work in ASP.
> >
> > The string I have is for example:
> > D:\Marco\ASIC2000\Images\Weapon\leo1schrägmit.jpg
> > Now I want to get rit of everything before the last "\" so that
> > leaves: leo1schrägmit.jpg
> >
> > One of the problems I have is that I never know what the string
> > looks like so I always looked for the last instance of "\" and cut
> > eveything left of it.
> >
> > In VB this code did it:
> >
> > Function LastInStr(strSearched As String, strSought As String) As Integer
> >
> > Dim intCurrVal As Integer
> > Dim intLastPosition As Integer
> >
> > intCurrVal = InStr(strSearched, strSought)
> > Do Until intCurrVal = 0
> > intLastPosition = intCurrVal
> > intCurrVal = InStr(intLastPosition + 1, strSearched, strSought)
> > Loop
> > LastInStr = intLastPosition
> >
> > End Function
> >
> > Can I use this function in ASP, and Where do I put it.
> > Or is there something else I can do?
> >
> > Regards
> > Marco
> > The NEtherlandsKrechting Guest
-
McKirahan #5
Re: Get last part of a string
"Krechting" <m.krechting@chello.nl> wrote in message
news:a71c776d.0312281546.1d025920@posting.google.c om...Are you familiar with "InStrRev"?> Hi All,
>
> I'm trying to get the last part of a string.
> In VB there's a function called lastinstr() who does the work.
> But it doesn't seem to work in ASP.
>
> The string I have is for example:
> D:\Marco\ASIC2000\Images\Weapon\leo1schrägmit.jpg
> Now I want to get rit of everything before the last "\" so that
> leaves: leo1schrägmit.jpg
>
> One of the problems I have is that I never know what the string
> looks like so I always looked for the last instance of "\" and cut
> eveything left of it.
>
> In VB this code did it:
>
> Function LastInStr(strSearched As String, strSought As String) As Integer
>
> Dim intCurrVal As Integer
> Dim intLastPosition As Integer
>
> intCurrVal = InStr(strSearched, strSought)
> Do Until intCurrVal = 0
> intLastPosition = intCurrVal
> intCurrVal = InStr(intLastPosition + 1, strSearched, strSought)
> Loop
> LastInStr = intLastPosition
>
> End Function
>
> Can I use this function in ASP, and Where do I put it.
> Or is there something else I can do?
>
> Regards
> Marco
> The NEtherlands
Description
Returns the position of an occurrence of one string within another, from the
end of string.
Syntax
InStrRev(string1, string2[, start[, compare]])
Here's how I use it to get the path to the current script:
Dim strSFN
strSFN = WScript.ScriptFullName
strSFN = Left(strSFN,InStrRev(strSFN,"\"))
(Note that the above snippet applies to WSH not ASP.)
McKirahan Guest
-
Paul #6
Re: Get last part of a string
Hi Marco
try this:
urlSplit = Split(Recordset.Fields("txtImagePathAndFile"),"\")
txtImagePathAndFile.Value = "Images/Weapon/" & urlSplit(UBound(urlSplit))
to explain:
the Split function returns an array of the components of the source string -
to access the last array member you need to get the index of the last member
using UBound and then access it by passsing this back into the array
in my earlier example, the path
"D:\Marco\ASIC2000\Images\Weapon\leo1schrägmit.jpg " gets passed into an
array as
urlSplit(0) --> D:
urlSplit(1) --> Marco
urlSplit(2) --> ASIC2000
urlSplit(3) --> Images
urlSplit(4) --> Weapon
urlSplit(5) --> leo1schrägmit.jpg
UBound(urlSplit) then returns the upper value of the index (in this case 5)
the value can then be accessed as urlSplit(UBound(urlSplit)) which is the
same as urlSplit(5) which gives you leo1schrägmit.jpg
as also posted, you could use InStrRev (probably more efficient as you don't
have to deal with arrays)
strPath = "D:\Marco\ASIC2000\Images\Weapon\leo1schrägmit.jpg "
WScript.Echo Right(strPath,Len(strPath)-InStrRev(strPath,"\"))
regards
paul
"Krechting" <m.krechting@chello.nl> wrote in message
news:a71c776d.0312290302.5bf733f3@posting.google.c om...news:<e7mYDPazDHA.1364@TK2MSFTNGP10.phx.gbl>...> Hi Paul,
>
> Tried what you told me but I only get a number returned.
> Don't know how to get the last part of the string extracted.
>
> txtImagePathAndFile.Value = "Images/Weapon/" &
> UBound(Split(Recordset.Fields("txtImagePathAndFile "),"\"))
>
> Returns: Images/Weapon/5
>
> What I want is Images/Weapon/somepicture.jpg
> Split and Ubound find the number of "/" in the string but i want the
> text that is behind that last "/"
>
> Regards
> MArco
>
>
> "Paul" <paul@nospam.com> wrote in messagesplit("D:\Marco\ASIC2000\Images\Weapon\leo1schrägm it.jpg","\")> > use split() and take the last entry
> >
> > e.g.
> >
> > urlSplit =Integer> > msgbox urlSplit(UBound(urlSplit))
> >
> > regards
> > paul
> >
> > "Krechting" <m.krechting@chello.nl> wrote in message
> > news:a71c776d.0312281546.1d025920@posting.google.c om...> > > Hi All,
> > >
> > > I'm trying to get the last part of a string.
> > > In VB there's a function called lastinstr() who does the work.
> > > But it doesn't seem to work in ASP.
> > >
> > > The string I have is for example:
> > > D:\Marco\ASIC2000\Images\Weapon\leo1schrägmit.jpg
> > > Now I want to get rit of everything before the last "\" so that
> > > leaves: leo1schrägmit.jpg
> > >
> > > One of the problems I have is that I never know what the string
> > > looks like so I always looked for the last instance of "\" and cut
> > > eveything left of it.
> > >
> > > In VB this code did it:
> > >
> > > Function LastInStr(strSearched As String, strSought As String) AsstrSought)> > >
> > > Dim intCurrVal As Integer
> > > Dim intLastPosition As Integer
> > >
> > > intCurrVal = InStr(strSearched, strSought)
> > > Do Until intCurrVal = 0
> > > intLastPosition = intCurrVal
> > > intCurrVal = InStr(intLastPosition + 1, strSearched,> > > Loop
> > > LastInStr = intLastPosition
> > >
> > > End Function
> > >
> > > Can I use this function in ASP, and Where do I put it.
> > > Or is there something else I can do?
> > >
> > > Regards
> > > Marco
> > > The NEtherlands
Paul Guest



Reply With Quote

