Home All Groups Group Topic Archive Search About
Author
26 Nov 2007 8:11 AM
HardySpicer
Suppose I have a string "mystring" of the form


mystring="c:\dir1\dir2\dir3\artist - title.mp3"

How can I strip the artist and song title from this in VB .net?

Thanks

Hardy

Author
26 Nov 2007 8:55 AM
Rick
Does this work for you:

System.IO.Path.GetDirectoryName(<fileName>)

Rick

Show quoteHide quote
"HardySpicer" <gyansor***@gmail.com> wrote in message
news:52a81e0b-3401-4c1a-8cec-39fa4e491937@e10g2000prf.googlegroups.com...
> Suppose I have a string "mystring" of the form
>
>
> mystring="c:\dir1\dir2\dir3\artist - title.mp3"
>
> How can I strip the artist and song title from this in VB .net?
>
> Thanks
>
> Hardy
Are all your drivers up to date? click for free checkup

Author
26 Nov 2007 12:01 PM
RB
Just to expand on Rick's answer, if you wanted to store the artist and
title separately then you could do something like:

(Note - handwritten code - may not compile!!)
   dim artist, title, both as string
   both = System.IO.Path.GetDirectoryName(<fileName>)
   artist = String.Split(both, "-")(0).Trim()
   title = String.Split(both, "-")(1).Trim()

Cheers,

RB.


Rick wrote:
Show quoteHide quote
> Does this work for you:
>
> System.IO.Path.GetDirectoryName(<fileName>)
>
> Rick
>
> "HardySpicer" <gyansor***@gmail.com> wrote in message
> news:52a81e0b-3401-4c1a-8cec-39fa4e491937@e10g2000prf.googlegroups.com...
>> Suppose I have a string "mystring" of the form
>>
>>
>> mystring="c:\dir1\dir2\dir3\artist - title.mp3"
>>
>> How can I strip the artist and song title from this in VB .net?
>>
>> Thanks
>>
>> Hardy
>
>
Author
26 Nov 2007 5:16 PM
HardySpicer
On Nov 27, 1:01 am, RB <owmdkbqziki***@mailinator.com> wrote:
Show quoteHide quote
> Just to expand on Rick's answer, if you wanted to store the artist and
> title separately then you could do something like:
>
> (Note - handwritten code - may not compile!!)
>    dim artist, title, both as string
>    both = System.IO.Path.GetDirectoryName(<fileName>)
>    artist = String.Split(both, "-")(0).Trim()
>    title = String.Split(both, "-")(1).Trim()
>
> Cheers,
>
> RB.
>
> Rick wrote:
> > Does this work for you:
>
> > System.IO.Path.GetDirectoryName(<fileName>)
>
> > Rick
>
> > "HardySpicer" <gyansor***@gmail.com> wrote in message
> >news:52a81e0b-3401-4c1a-8cec-39fa4e491937@e10g2000prf.googlegroups.com...
> >> Suppose I have a string "mystring" of the form
>
> >> mystring="c:\dir1\dir2\dir3\artist - title.mp3"
>
> >> How can I strip the artist and song title from this in VB .net?
>
> >> Thanks
>
> >> Hardy

Thank you - you have all been helpful.

Hardy
Author
26 Nov 2007 8:00 PM
HardySpicer
On Nov 27, 1:01 am, RB <owmdkbqziki***@mailinator.com> wrote:

>    dim artist, title, both as string
>    both = System.IO.Path.GetDirectoryName(<fileName>)
>    artist = String.Split(both, "-")(0).Trim()
>    title = String.Split(both, "-")(1).Trim()
>
> Cheers,
>
> RB.
>
>

This is good but I get an error in compilation
Overload resolution failed because no accessible '<method>' can be
called without a narrowing conversion:


You have made a call to an overloaded method, but the compiler cannot
find a method that can be called without a narrowing conversion. A
narrowing conversion changes a value to a data type that might not be
able to precisely hold some of the possible values.

Bit confused about this.. It says to use Option Strict Off but it is
already off.

Hardy
Author
26 Nov 2007 10:03 PM
Jack Jackson
On Mon, 26 Nov 2007 12:00:27 -0800 (PST), HardySpicer
<gyansor***@gmail.com> wrote:

Show quoteHide quote
>On Nov 27, 1:01 am, RB <owmdkbqziki***@mailinator.com> wrote:
>
>>    dim artist, title, both as string
>>    both = System.IO.Path.GetDirectoryName(<fileName>)
>>    artist = String.Split(both, "-")(0).Trim()
>>    title = String.Split(both, "-")(1).Trim()
>>
>> Cheers,
>>
>> RB.
>>
>>
>
>This is good but I get an error in compilation
>Overload resolution failed because no accessible '<method>' can be
>called without a narrowing conversion:
>
>
>You have made a call to an overloaded method, but the compiler cannot
>find a method that can be called without a narrowing conversion. A
>narrowing conversion changes a value to a data type that might not be
>able to precisely hold some of the possible values.
>
>Bit confused about this.. It says to use Option Strict Off but it is
>already off.

Don't use Option Strict Off, it will only cause you trouble.  Try
this:

    dim artist, title, both, mystring as string
    dim fname() as string

    mystring="c:\dir1\dir2\dir3\artist - title.mp3"

    fname = System.IO.Path.GetFileNameWithoutExtension(mystring)
    both = fname.Split("-"c)
    artist = both(0).Trim()
    title = both(1).Trim()
Author
26 Nov 2007 11:11 AM
Chris Diver
HardySpicer wrote:
> Suppose I have a string "mystring" of the form
>
>
> mystring="c:\dir1\dir2\dir3\artist - title.mp3"
>
> How can I strip the artist and song title from this in VB .net?
>
> Thanks
>
> Hardy

tempstring = IO.Path.GetFileNameWithoutExtension(mystring)

'Providing there is only one -
Dim ArtTit As String() = tempstring.Split("-")
artist = ArtTit(0).Trim
title = ArtTit(1).Trim


Chris
Author
26 Nov 2007 11:35 AM
rowe_newsgroups
On Nov 26, 3:11 am, HardySpicer <gyansor***@gmail.com> wrote:
> Suppose I have a string "mystring" of the form
>
> mystring="c:\dir1\dir2\dir3\artist - title.mp3"
>
> How can I strip the artist and song title from this in VB .net?
>
> Thanks
>
> Hardy

Though I don't recommend it for this example (I prefer using the Path
object too) remember you can use Regex to parse strings if you need
some very specific matching requirements. Just remember that Regex is
hard on maintenance due to the cryptic match strings and is often more
costly in performance than other methods of string parsing.

Thanks,

Seth Rowe
Author
26 Nov 2007 11:54 AM
Cor Ligthert [MVP]
Hallo,

Though I don't recommend it for this example (I prefer using the Path
class too) remember you can use two times indexofLast in combination with
substring too

http://msdn2.microsoft.com/en-us/library/system.string.lastindexof(VS.71).aspx

Something as this typed in this message

dim myindex as integer = mystring.lastindexof(".")
dim myartist as string

if myindex.lastindexof(".") <> -1 then
    mynewstring = mystring.substring(0,myIndex)
    myindex = mynewstring.lastindexof(".")
    if myindex.lastindexof(".") <> -1 then
        myartist = mynewstring(myindex)
    endif
endif

It is not checked however a direct answer on your question what I would
never use.

Cor




Show quoteHide quote
"HardySpicer" <gyansor***@gmail.com> schreef in bericht
news:52a81e0b-3401-4c1a-8cec-39fa4e491937@e10g2000prf.googlegroups.com...
> Suppose I have a string "mystring" of the form
>
>
> mystring="c:\dir1\dir2\dir3\artist - title.mp3"
>
> How can I strip the artist and song title from this in VB .net?
>
> Thanks
>
> Hardy

Bookmark and Share

Post Thread options