Convert a String to a Number

How can i convert a character to a number, so that the result is only numerical digits, and would always be the same, besides 26 (plus non-alpha characters) if-then statements.

like, A = 1 and A always equals 1

so if I had the string:  1234A

after converting, I would get the result:  12341

A doesn't necessarily have to = 1, or even a single digit.  It just has to equal a numerical... number.

12/29/2007 12:26:03 AM 93655 articles. 5 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 29

perhaps you can do something like this. 

Store your letters in an array A and maintain a cooresponding array B that has the numeric equivalent you would want to replace the letter with.

When an alpha character is found in array A, you simply substitute the value from array B at the same index position giving you repeatable replacements.

        Dim arA As Char() = {"A", "B", "C", "D", "E"}
        Dim arB As Char() = {"1", "2", "3", "4", "5"}

        Dim test As String = "1234A"

        'convert test string into a char array
        Dim chars As Char() = test.ToCharArray

        'for each char in our input string
        For index As Integer = 0 To chars.Length - 1
            'find each char in the first array
            'converting to uppercase as we go
            'to match how we entered them in our 1st array
            Dim i As Integer = Array.IndexOf(arA, Char.ToUpperInvariant(chars(index)))

            'if found, use the char in the same index position from the 2nd array
            'and replace the character
            If i >= 0 Then chars(index) = arB(i)


        'now convert the char array back into a string
        test = New String(chars)

        'test will now equal "12341"
Mike Banavige

Need a site code sample in a different language? Try converting it with:
12/29/2007 1:00:04 AM

Yeah, that would work.  But i was looking for something even simpler, like using an ASCII code, or converting the string as a whole to hex.

 Like ConvertToSomething(125t-12A) = 23098432 or whatever.

 Maybe i could combine that with your idea, but instead of using arrays, just iterate each character and if it is non-numeric, convert it to something that is numeric.

 Thanks for your suggestions.

12/29/2007 1:15:41 AM

Try something like this:


string x = "50";

Int32 i = Int32.Parse(x);

Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
12/29/2007 1:19:24 AM


... just iterate each character and if it is non-numeric, convert it to something that is numeric.

In order to distinguish between the characters that are numeric digits and those that are not, i think you will need to iterate.  Here's a simpler iteration.

        Dim sb As New StringBuilder
        Dim test As String = "1234A"
        For Each c As Char In test.ToCharArray
            If Char.IsDigit(c) Then
            End If
        test = sb.ToString
Mike Banavige

Need a site code sample in a different language? Try converting it with:
12/29/2007 1:25:21 AM

Similar Artilces:

How To Convert web template to Forms Template
I need  Convert web template to Forms Template   There are some free c# to vb converters out there which will allow you to upload a project and convert it to vb.   The programming models for windows forms and web projects are very different there is no way to convert a web to windows forms project.      Silverlight-helpVb TipsSpace Coast .Net User Group Hey Ajax-y, This tool really helps all programmers. I thought I would share this wit...

Convert Number In Strings to Numeric Form
Hi, I need some help in converting strings that contain numbers back into numeric form. Apparently, when I sort string formatted number, the arrangement was according to alphanumeric order (eg. 1, 10,11,2,20,21,3,30... ). Thanks, TY on Mon, 15 Apr 2002 13:14:40 GMT, Mok T.Y.-R15382 wrote: > I need some help in converting strings that contain numbers back into > numeric form. Apparently, when I sort string formatted number, the > arrangement was according to alphanumeric order (eg. 1, > 10,11,2,20,21,3,30... ). Are you using the correct comparison operator? As ...

how to convert form string to number and back?
Hello, I have to read and write some number-values form/to the ultralite-DB. In the reference-DB (Sybase) the fields are defined as numeric(16,6). I have tried the following in CodeWarrier: 1) Defne the fields in the sql declare section as static char fieldname[17]. This works for download / upload, and showing the values. But if I have to UPDATE the table I get an SQLE_CONVERSION_ERROR 2) Define the fields as DECL_DECIMAL(16,6). Now I can't show the value and can't get the Palm-field and write it to the defined variable because I have only found a sample code to get and...

Implementing .Net Form into an web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

converting PowerBuilder app to .NET web forms
Hello Version 11.1 build 8123/sql server. We access PowerBuilder through SoftGrid. We are planning on converting our pb apps to .net web forms. We need IIS on our development server. We cannot have IIS installed on our desktops. How would I go about explaining to our IT dept how we need IIS installed for us to proceed with .NET? Second Question: We also need the Microsoft .NET Framework 2.0. Is this also something that would typically be installed on individual desktops? any help would be greatly appreciated Sincerely Tony With 11.1, you have the option of deploying to an...

Converting Windows Form to Web Form
Is it possible to convert a windows form to a web form? I want to convert a VB 6.0 application I worked on for a year(24 forms) to a web application. My plan is to migrate form VB 6.0 to VB .NET and then to ASP.NET Thank u in advance. well an ASP.NET app can do anything that a VB6 app can do, that is for sure :) so it is possible the question is how easy? how well did you keep separate business from user-interface logic? it may be as simple as cuttting/pasting a bunch of methods, and dropping a few visual components to call them. to maintain full compliance with...

PB 11 .Net Web Form return a simple string?
Is it possible to create a pb 11 webform app that will accept input parms and return a simple string in response? Not trying to convert an existing app, I just want to be able to create web forms that can accept input parms, query a database to determine the answer based on the parms, and then return the answer in string format. For example, if I typed in the following url it might return "John Doe" as a simple string. WebForm is the wrong direction. You can create a .net assembly and use this inside asp. No big deal. ...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

convert Windows Forms UIs to Web Forms
that If i made an application in .How i can migrate to asp.netThanks Hi VGTA,There is no automatic wizard that will convert an ASP.NET app to WinForms, or a WinForms app to ASP.NET.  However, a number of the concepts are similar between the two models and you will be able to re-use all of your non-UI specific code.  The broader .NET Framework class library is also the same.Hope this helps,Scott I found a tool with which you can convert Windows Forms to its corresponding Web Form counterparts.

.Net Web Form & Web Service Deployment
Hi all I have written some test web services and some web form applications and deployed them to my IIS. That's fine but I now want to deploy them to my real IIS server. I have created an msi for each but the problem is I seem to only be able to deploy to the default web site. Our default web site is turned off and instead we use several other sites. Does anybody happen to if Powerbuilder 11 supports non default web sites? If not do I need to hack the msi and if so can anybody suggest a suitable tool. I have Orca but it's not very friendly. Unless of course I knew exactly w...

How to convert web form(web page) to a word document
Hi Guys.Can any one give me a hint on how to  convert a web form (a web page) to a word document.Thank You...

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

how to convert website to web site
Can we convert a website(VB.NET) to website in VS2005???mahmood Why do you want to convert VB into C#? you can create new modules for the site in C#, and they can co-exist in the same system. If you have some specific requirements, then use online tools to convert into c# to convert the codebehind files. Most probably the .aspx file will remain unchanged, but you might need to make some changes here and there.You will get lots of converters online by just googling it. I would strongly recommend avoiding converting codes, as I have faced the horrors of the process. Pr...

Convert VB.Net Web Site to Web Application Project
 I am working with Visual Studio Pro SP1 and had some problems converting an old VB.Net web site into a VB.Net Web Application Project.  I followed the advice offered here ( ), but ran into a few kinks when using the process on a VB project.  The Problem:After creating a new Web Application Project, copying in the old files, and running the "Convert to Web Application Project" process, the site would no longer build.  Any classes stored in the "Old_App_Code" folder (previously named...

Web resources about - Convert a String to a Number -

List of converts to Buddhism - Wikipedia, the free encyclopedia
Ajahn Brahm (born 1951), Religious teacher and student of the late Thai monk Ajahn Chah . Currently he is the abbot of the Bodhinyana Monastery, ...

Facebook Timeline For Pages: 8 Million Converts, 29 Million To Go
... reach to 98 percent of users who liked its page, as well as to double its engagement rate, during a 28-day period. Dr. Pepper hasn’t yet converted ...

Facebook stock roundup: Execs offload more stock, directors convert shares
... Bowles, the former co-chair of the now-defunct National Commission on Fiscal Responsibility and Reform, and Reed Hastings, Netflix CEO, converted ...

How to Convert Leads Into Buying Customers - The 9 Step Sales Process EVERYONE Should Use
... School of Business in Toronto on the topics of Sales and Entrepreneurship. I shared with them the sales process that I find How to Convert Leads ...

Bitcoin : Should I convert my savings to Bitcoin?
Answer (1 of 7): You should think of this question as "Should I invest all my savings in Bitcoin?", and not "Should I have my savings denominated ...

Coordinates - Calculate and Convert a Position on the App Store on iTunes
Get Coordinates - Calculate and Convert a Position on the App Store. See screenshots and ratings, and read customer reviews.

Catholics should not convert Jews, says Vatican, in push against anti-Semitism
... 50 years since the Vatican's repudiation of the concept of Jewish guilt for Jesus' death.  Vatican City: Catholics should not try to convert ...

Today’s apps gone free: BlockBear, Stock Grader, PDF Smart Convert and more
Block ads and other annoying content, take the emotion out of investing, and convert almost anything into a PDF with todays collection of apps ...

Ford patents rear wheel that converts into a unicycle
Filed under: Government/Legal , Green , Ford , Green Driving , Motorcycle , Electric Ford is thinking about allowing drivers to remove a rear ...

How to convert your old VHS tapes to DVD with this software
Remember those old VHS tapes you have sitting in the corner? Convert them into DVDs with this affordable software so you can easily watch them ...

Resources last updated: 1/6/2016 2:12:17 PM