473,466 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Parsing String to Integer

3 New Member
How do I transfer numeric values of a string which has both numbers, character and symbols to integer

Thanks
Nov 11 '08 #1
6 2391
myusernotyours
188 New Member
Hi,
The String API has methods that you can easily use to find any characters you want from the string. Once you have for example found a number use the String.parseInt() method to convert it to an integer.

Consider the methods charAt(), contains(), subString() e.t.c.

You can get a better response if you tell us exactly what you are trying to do and where you are particularly stuck.

You may want to brush up on the String class and the methods therein.

Regards,

Alex.
Nov 11 '08 #2
r035198x
13,262 MVP
You need to get the numbers out first.

Hint: Splitting the string on "\\D" gives an array containing all the numbers and a lot of empty strings.
Nov 11 '08 #3
lkjayarathna
3 New Member
Thanks guys for the quick reply,

What I am trying to do is, I have a List which shows few string & int in one row as a one string.

So i want to get a substring of the the final string, which contains the (initial int value)numeric value i want. So then I can use it to do the rest of the calculations.

But I cannot use Integer.parseInt(mysubstring) to pass tp a string because it contains both numeric and characters.

Thanks
Nov 11 '08 #4
JosAH
11,448 Recognized Expert MVP
Reread reply #3 again; a slightly better regular expression to use is "\\D+"; it
results in a smaller array.

kind regards,

Jos
Nov 11 '08 #5
lkjayarathna
3 New Member
I have no idea what u guys talking about D
Nov 11 '08 #6
Ganon11
3,652 Recognized Expert Specialist
Go to Google and search for String.java.

Click the first link and find the split() method explanation. (here's a link)

While you may think you have to learn an entirely new language, Jos and r0 have already given you the string needed to split your String. The rest is just some reading and code attempts.

Hope this helps!
Nov 12 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: george young | last post by:
For each run of my app, I have a known set of (<100) wafer names. Names are sometimes simply integers, sometimes a short string, and sometimes a short string followed by an integer, e.g.: 5, 6,...
0
by: bj0011 | last post by:
I am trying to parse an XML file obtained from a public WebService (see below). This file does not seem to be loading into a .NET XmlDocument right (I think it is because of all of the <Item Name=""...
21
by: google | last post by:
I'm trying to implement something that would speed up data entry. I'd like to be able to take a string, and increment ONLY the right-most numerical characters by one. The type structure of the...
18
by: Atara | last post by:
In my apllication I use the following code: '-- My Code: Public Shared Function strDate2Date(ByVal strDate As String) As System.DateTime Dim isOk As Boolean = False If (strDate Is Nothing)...
2
by: irishdudeinusa | last post by:
Hello Everyone, I have been working a webservice where I can use it in other applications that I am working on. However, I am running into a problem with the data returned and I was wondering if...
2
by: christianlott1 | last post by:
What this function attempts to do is remove the first string of numbers in an address field. I get "invalid procedure call or argument" for line: ---- j = Asc(Mid(Original, i, 1)) ---- ...
3
by: mtuller | last post by:
Alright. I have tried everything I can find, but am not getting anywhere. I have a web page that has data like this: <tr > <td headers="col1_1" style="width:21%" > <span class="hpPageText"...
6
by: korovev76 | last post by:
Hello everybody, I'm new to python (...I work with cobol...) I have to parse a file (that is a dbIII file) whose stucture look like this: |string|, |string|, |string that may contain commas...
7
by: cephal0n | last post by:
Hi there! I've been racking my brains out for 4 days and still not getting why is msaccess stubborn about string parsing, first I have a table named tblItems, this table has columns: ProductItem,...
5
by: javanianewbie | last post by:
Hello, I am having trouble when I read in a a file and parsing part of it as an int using substring. Here is the code I have: String input = ""; while(readFile.hasNextLine())
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.