Home All Groups Group Topic Archive Search About

Equivalent to Mid function but read from right of the string

Author
5 Apr 2005 1:51 PM
kd
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

Author
5 Apr 2005 2:17 PM
Paul Clement
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)
Author
5 Apr 2005 2:40 PM
Cor Ligthert
Kd
Roughly typed.
\\\
dim s as string = "kd"
s = s.substring(0,s.length-1)
///
Or
Author
5 Apr 2005 3:15 PM
Andrew Morton
> 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?

s2=Left(s1, Len(s1)-1)

> 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.

s2=StrReverse(Mid(s1, 2))

Andrew
Author
5 Apr 2005 4:03 PM
Herfried K. Wagner [MVP]
"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/>
Author
5 Apr 2005 4:24 PM
Robert S. Liles
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
Author
5 Apr 2005 5:49 PM
Robert S. Liles
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
Author
6 Apr 2005 2:29 AM
lgbjr
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
Author
6 Apr 2005 10:23 AM
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
>
>
>