|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Equivalent to Mid function but read from right of the stringHi All,
I have a string variable, whose length is not constant. I need to extract the whole string, except the last character in the string. Is there any string function that can do this? Something like the Mid function, but extracts the string from the right; so that I could extract the string from 2nd character till the end of the string, but start reading from the right. Thanks. kd On Tue, 5 Apr 2005 06:51:03 -0700, "kd" <k*@discussions.microsoft.com> wrote: ¤ Hi All,¤ ¤ I have a string variable, whose length is not constant. I need to extract ¤ the whole string, except the last character in the string. Is there any ¤ string function that can do this? ¤ ¤ Something like the Mid function, but extracts the string from the right; so ¤ that I could extract the string from 2nd character till the end of the ¤ string, but start reading from the right. Probably more than one way to do this, but the Substring method of the String class is similar to the Mid function. Paul ~~~~ Microsoft MVP (Visual Basic) Kd
Roughly typed. \\\ dim s as string = "kd" s = s.substring(0,s.length-1) /// Or > I have a string variable, whose length is not constant. I need to s2=Left(s1, Len(s1)-1)> extract the whole string, except the last character in the string. Is > there any string function that can do this? > Something like the Mid function, but extracts the string from the s2=StrReverse(Mid(s1, 2))> right; so that I could extract the string from 2nd character till the > end of the string, but start reading from the right. Andrew "kd" <k*@discussions.microsoft.com> schrieb: \\\> I have a string variable, whose length is not constant. I need to extract > the whole string, except the last character in the string. Is there any > string function that can do this? > > Something like the Mid function, but extracts the string from the right; > so > that I could extract the string from 2nd character till the end of the > string, but start reading from the right. Const Text As String = "axxxxxxxxxxxxxxxxz" ' Everything except last character. MsgBox(Strings.Left(Text, Len(Text) - 1)) 'Everything except first character. MsgBox(Strings.Right(Text, Len(Text) - 1)) /// -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Dim MyString as string = "Some useful data!"
Dim MyPartialString as string then use MyPartialString = MyString.Substring(0,MyString.Length - 1) or MyPartialString = Microsoft.VisualBasic.Left(MyString,MyString.Length - 1) Bobbo If you really just want a FUNCTION to do this, use
Private Function SubstringRev(ByVal InputString as String, ByVal Start as Integer) as String Return InputString.Substring(0, InputString.Length - Start) End Function Bobbo You may want to try something like this:
Dim strlen as Integer Dim MyString as String strlen=MyString.Length MyString=Mystring.Substring(1,strlen-1) This will give you everything but the last character of the string, regardless of the length of the string. However, if the string length is 0, you'll get an exception, so you'll need to test the string length first. HTH Lee Show quoteHide quote "kd" <k*@discussions.microsoft.com> wrote in message news:8E56175F-2E5C-4F37-8D7C-D6B279C02288@microsoft.com... > Hi All, > > I have a string variable, whose length is not constant. I need to extract > the whole string, except the last character in the string. Is there any > string function that can do this? > > Something like the Mid function, but extracts the string from the right; > so > that I could extract the string from 2nd character till the end of the > string, but start reading from the right. > > Thanks. > kd Hi All,
Thanks for the so many different ways to do it. Regards, kd Show quoteHide quote "lgbjr" wrote: > You may want to try something like this: > > Dim strlen as Integer > Dim MyString as String > strlen=MyString.Length > MyString=Mystring.Substring(1,strlen-1) > > This will give you everything but the last character of the string, > regardless of the length of the string. However, if the string length is 0, > you'll get an exception, so you'll need to test the string length first. > > HTH > Lee > > "kd" <k*@discussions.microsoft.com> wrote in message > news:8E56175F-2E5C-4F37-8D7C-D6B279C02288@microsoft.com... > > Hi All, > > > > I have a string variable, whose length is not constant. I need to extract > > the whole string, except the last character in the string. Is there any > > string function that can do this? > > > > Something like the Mid function, but extracts the string from the right; > > so > > that I could extract the string from 2nd character till the end of the > > string, but start reading from the right. > > > > Thanks. > > kd > > >
Opening a browser from vb.net from
datagrid filled from a list need clarification from M S Herfried K. Wagner Help using Right() string function? Parameter it doesn't work (for me) II Datagrid Question How to set the default value of a date picker to nothing (blank) Parameter it doesn't work (for me) IIII get no-integer returned from exe Setup for VS.Net 2003 |
|||||||||||||||||||||||