|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Disecting StringsSuppose 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 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 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 > > 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 Thank you - you have all been helpful.> 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 Hardy On Nov 27, 1:01 am, RB <owmdkbqziki***@mailinator.com> wrote:
> dim artist, title, both as string This is good but I get an error in compilation> both = System.IO.Path.GetDirectoryName(<fileName>) > artist = String.Split(both, "-")(0).Trim() > title = String.Split(both, "-")(1).Trim() > > Cheers, > > RB. > > 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 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: Don't use Option Strict Off, it will only cause you trouble. Try> >> 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. 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() HardySpicer wrote:
> Suppose I have a string "mystring" of the form tempstring = IO.Path.GetFileNameWithoutExtension(mystring)> > > mystring="c:\dir1\dir2\dir3\artist - title.mp3" > > How can I strip the artist and song title from this in VB .net? > > Thanks > > Hardy 'Providing there is only one - Dim ArtTit As String() = tempstring.Split("-") artist = ArtTit(0).Trim title = ArtTit(1).Trim Chris On Nov 26, 3:11 am, HardySpicer <gyansor***@gmail.com> wrote:
> Suppose I have a string "mystring" of the form Though I don't recommend it for this example (I prefer using the Path> > mystring="c:\dir1\dir2\dir3\artist - title.mp3" > > How can I strip the artist and song title from this in VB .net? > > Thanks > > Hardy 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 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
Removing reference type members from a generic list clone
vs2008 or not Creating a Web Service (Service, not Client) from WSDL XML Deserializer problem Multithreading Invoke Workaround Convert code line to VB Bug in VWD 2008 Express? Editing an indexed PixelFormat Question about Application Layout Where are use scoped settings stored? |
|||||||||||||||||||||||