By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

Equivalent to Mid function but read from right of the string

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Tue, 5 Apr 2005 06:51:03 -0700, "kd" <kd@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)
Nov 21 '05 #2

P: n/a
Kd
Roughly typed.
\\\
dim s as string = "kd"
s = s.substring(0,s.length-1)
///
Or
Nov 21 '05 #3

P: n/a
> 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
Nov 21 '05 #4

P: n/a
"kd" <kd@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/>

Nov 21 '05 #5

P: n/a

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.Lengt h - 1)

Bobbo
Nov 21 '05 #6

P: n/a
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
Nov 21 '05 #7

P: n/a
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" <kd@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.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

Nov 21 '05 #8

P: n/a
kd
Hi All,

Thanks for the so many different ways to do it.

Regards,
kd

"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" <kd@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.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


Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.