How do I convert string to numeric in VB.NET 2003 ?
Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle
then not convert.
Regards,
Tee 9 8232
On Sep 29, 11:03*am, "engteng" <pass...@gmail. comwrote:
How do I convert string to numeric in VB.NET 2003 ?
Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle
then not convert.
Regards,
Tee
In my idea, first you should remove P by taking only numeric part
using substring function, then you're ready to cast it to Integer or
Long using CInt or CLng depending on the range as follows:
' For P50001
Dim num1 As String = "P50001"
num1 = num1.Substring( 1)
'Proove that 50001 is now an Int32
MsgBox(num1 & " is " & _
CInt(num1).GetT ype.Name.ToStri ng)
' For 50001P
Dim num2 As String = "50001P"
num2 = num2.Substring( 0, 5)
MsgBox(num2 & " is " & _
CInt(num2).GetT ype.Name.ToStri ng)
'.........
Hope this helps,
Onur Güzel
Hello Tee,
if the "P" always is the single first or last character you could
write something like:
_______________ _______________ _____________
dim strX as string
dim dblValue as Short
strX="P50001"
if LCase(Left(strX ,1))="p" then
dblvalue = val(mid(strX,2) )
elseif LCase(Right(str X,1))="p" then
dblvalue = val(left(strX,L en(strX)-1))
else
dblvalue = 0
end if
_______________ _______________ _____________
If the character may vary you could change the code into something
like:
_______________ _______________ _____________
if Not IsNumeric(LCase (Left(strX,1))) then
_______________ _______________ _____________
(I didn't check it with the debugger so I hope it's free of errors)
Good luck,
Lorenz
Hi Lorenz,
Generally it is better to use a string comparison method than convert
strings to lower case or upper case for the purpose of a case insensitive
match, eg:
If s.StartsWith("P ", StringCompariso n.CurrentCultur eIgnoreCase) Then
s = s.Substring(1)
ElseIf s.EndsWith("P", StringCompariso n.CurrentCultur eIgnoreCase) Then
s = s.Substring(0, s.Length - 1)
End If
value = CInt(s)
"Lorenz Hölscher" <in******@softw are-dozent.dewrote in message
news:e4******** *************** ***********@p25 g2000hsf.google groups.com...
Hello Tee,
if the "P" always is the single first or last character you could
write something like:
_______________ _______________ _____________
dim strX as string
dim dblValue as Short
strX="P50001"
if LCase(Left(strX ,1))="p" then
dblvalue = val(mid(strX,2) )
elseif LCase(Right(str X,1))="p" then
dblvalue = val(left(strX,L en(strX)-1))
else
dblvalue = 0
end if
_______________ _______________ _____________
If the character may vary you could change the code into something
like:
_______________ _______________ _____________
if Not IsNumeric(LCase (Left(strX,1))) then
_______________ _______________ _____________
(I didn't check it with the debugger so I hope it's free of errors)
Good luck,
Lorenz
Hi Tee,
You can try:
value = CInt( s.Trim("P"c, "p"c))
"engteng" <pa*****@gmail. comwrote in message
news:eH******** ******@TK2MSFTN GP03.phx.gbl...
How do I convert string to numeric in VB.NET 2003 ?
Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle
then not convert.
Regards,
Tee
Hi Bill,
you're right for sure. As you might have seen I usually work with
Office-VBA with no SubString-Method und its IgnoreCase-Parameter until
now...
bye, Lorenz
Tee,
dim Example as string = "P50001p".tolow er.Trim("p") http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx
Cor
"engteng" <pa*****@gmail. comschreef in bericht
news:eH******** ******@TK2MSFTN GP03.phx.gbl...
How do I convert string to numeric in VB.NET 2003 ?
Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle
then not convert.
Regards,
Tee
On Sep 29, 2:06*pm, "Cor Ligthert [MVP]" <notmyfirstn... @planet.nl>
wrote:
Tee,
dim Example as string = "P50001p".tolow er.Trim("p")
http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx
Cor
"engteng" <pass...@gmail. comschreef in berichtnews:eH* *************@T K2MSFTNGP03.phx .gbl...
How do I convert string to numeric in VB.NET 2003 ?
Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle
then not convert.
Regards,
Tee- Hide quoted text -
- Show quoted text -
Why are you trying to lower P? OP just wants to convert "P50001 to
50001" or "50001P to 50001". Plus, trimming 'P' is not enough alone,
also the string type must be converted to a numeric type such as
Integer for further usage. In this case, it's proper to take the part
of the string value that can be casted to Integer using CInt or
Convert.ToInt32 etc. (without 'P').
Thanks,
Onur G.
Onur,
The first I agree, it is converting the P in the middle as well, to lower.
But how can you convert a string with a P in the middle to a what you call a
numeric?
That can only by those who call a string with all numeric characters a
numeric, and therefore I did not extend the code for that part.
(By the way, I have tried the code, with that what you did, you can do the
same, as you then set a simple Cint before it, you can use it as any real
numeric value instead of a string, however this can in my idea never been
done in the way the Op was asking).
Cor
"kimiraikko nen" <ki************ *@gmail.comschr eef in bericht
news:10******** *************** ***********@x41 g2000hsb.google groups.com...
On Sep 29, 2:06 pm, "Cor Ligthert [MVP]" <notmyfirstn... @planet.nl>
wrote:
Tee,
dim Example as string = "P50001p".tolow er.Trim("p")
http://msdn.microsoft.com/en-us/library/d4tt83f9.aspx
Cor
"engteng" <pass...@gmail. comschreef in
berichtnews:eH* *************@T K2MSFTNGP03.phx .gbl...
How do I convert string to numeric in VB.NET 2003 ?
Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle
then not convert.
Regards,
Tee- Hide quoted text -
- Show quoted text -
Why are you trying to lower P? OP just wants to convert "P50001 to
50001" or "50001P to 50001". Plus, trimming 'P' is not enough alone,
also the string type must be converted to a numeric type such as
Integer for further usage. In this case, it's proper to take the part
of the string value that can be casted to Integer using CInt or
Convert.ToInt32 etc. (without 'P').
Thanks,
Onur G.
How about using regular expressions
Dim SomeValue As String = "P500P01"
Dim SomeNumber As Integer = 0
Dim objRegEx As New Regex("[p]")
SomeNumber = CInt(objRegEx.R eplace(SomeValu e.ToLower, ""))
"engteng" <pa*****@gmail. comwrote in message
news:eH******** ******@TK2MSFTN GP03.phx.gbl...
How do I convert string to numeric in VB.NET 2003 ?
Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle
then not convert.
Regards,
Tee
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Vijai Kalyan |
last post by:
I wrote the following function as a curiosity:
template<typename SourceType,
typename DestinationType>
DestinationType NumericCast(const SourceType& value) {
std::wstringstream strbuf;
strbuf << value << std::endl ;
strbuf.flush();
DestinationType convalue;
strbuf >> convalue;
|
by: aevans1108 |
last post by:
expanding this message to microsoft.public.dotnet.xml
Greetings
Please direct me to the right group if this is an inappropriate place
to post this question. Thanks.
I want to format a numeric value according to an arbitrary regular
expression.
|
by: Golan |
last post by:
Hi,
I need to convert a Binary value to Decimal. I've been told that the
value is an unsigned one. How can I do this?
I use memcpy into an unsigned char variable, but when I print the
value I got a negative value.
For example if I'm using the xd -c (Unix) on the file, I can see the
value FFFFFFFFFFFFFFA2 which using the memcpy as described...
|
by: Convert TextBox.Text to Int32 Problem |
last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function and there you have it. So I enquired and found the Convert class with it's promising ToInt32 method, great... but it doesn't work. The thing keeps...
|
by: Ken Varn |
last post by:
I have an unknown numeric Type object passed into a function. I want to run
a conversion on a string to convert the string to that Type object and
return an object of that type. Is there some way to do a generic cast or
conversion on the type?
Here is sort of what I want to do:
object MyFunc(Type T, String Str)
{
object o;
| |
by: Joergen Bech |
last post by:
Is there a function in the .Net 1.1 framework
that will take, say, a string containing Scandinavian
characters and output the corret HTML entities, such
as
æ
ø
å
etc.
|
by: Drew |
last post by:
Hi All:
I know I am missing something easy but I can't find the problem! I
have a program which reads an integer as input.
The output of the program should be the sum of all the digits in the
integer that was entered.
So, if 353 was entered, the output should be 11.
|
by: simonZ |
last post by:
Why this don't work:
Boolean test;
String testValue;
testValue="0";
test=System.Convert.ToBoolean(testValue);
How can I convert string to boolean?
|
by: dba_222 |
last post by:
Dear Experts,
Ok, I hate to ask such a seemingly dumb question, but I've
already spent far too much time on this. More that I
would care to admit.
In Sql server, how do I simply change a character into a number??????
In Oracle, it is:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |