473,465 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reading a value from a string.

If I had a string value of

"1 - This is the number one"

Is there a method for reading just the integer value 1? I was looking and I found the method for adding each byte into an array. I supposed that I could read the first array value but that seemed to be quite a bit more work than was required. What method would you use?
Oct 5 '10 #1
5 2136
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
You can split the string on some delimiter(Say '-' in this case). And then extract first part from resulting array.

Regards
Dheeraj Joshi
Oct 5 '10 #2
pbrockway2
151 Recognized Expert New Member
You don't what the possible values of this integer are.

If the integer value is just one digit long you could use the String substring(int,int) method to make a String with just the first character. The the static Integer method parseInt() can be used to find the int value corresponding to this string. (There are also String and Character methods that will work with the first character directly - not as a one digit string)
Oct 5 '10 #3
I was thinking something very similar to that, then I found...

Expand|Select|Wrap|Line Numbers
  1. char name = stringName.charAt(0);
This is exactly what I was looking for. I found this right after I asked the question. I swear sometimes I do not find an answer myself, until I ask a question. After that I just converted the char to an INT and all was good. Perhaps not the most "elegant" method but it works great for what I am using it for.
Oct 5 '10 #4
In case you are wondering. I have created an array of buttons. I wanted the label on the button to be more descriptive. So...

Expand|Select|Wrap|Line Numbers
  1. center[i] = new JButton("Text " + (i+1) " more text " + arrayValue[i] + " more text " + array2value[i]);
Each button is created with accompanying text inside of the loop. So now the action listener uses getText and charAt(5) gets the number. I wasn't certain how I wanted to accomplish getting the value from the button. I needed this value to accomplish further calculations based on the array values. This is working perfectly now, because the number (i+1) is static and matches the array after I subtract 1 from the converted char.
Oct 5 '10 #5
pbrockway2
151 Recognized Expert New Member
I found this right after I asked the question. I swear sometimes I do not find an answer myself, until I ask a question.
Same with me! I'm glad you've got it worked out.
Oct 5 '10 #6

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

Similar topics

4
by: Mateo | last post by:
Hi! I have labels on my page (some are web forms controls, and some are plain HTML labels), and I need Mozilla compatibile way for reading label value. For example, in IE I can use this:...
1
by: Ron | last post by:
I have a method that generates an string in XML format and passes it to be processed. The string is in the following format: <grandparent> <parent> <child1>text</child1> <child2>text...
0
by: Ron | last post by:
I have a method that generates an string in XML format and passes it to be processed. The string is in the following format: <grandparent> <parent> <child1>text</child1> <child2>text...
2
by: Claire | last post by:
This works ok in a new empty project. I write an empty string to a file. Looking at the file with a hex editor, there's a single byte of value zero. I expect this, it's utf8 encoding and this is...
1
by: iano | last post by:
Reading the commandline in VB6 was simple. Finding an example for VbNet has been challenging. Would someone please post one? Thanks, IanO
2
by: ES Kim | last post by:
Hi everyone, Sometimes I need to tokenize a string and convert it into some value. For example, "123.45" with predifined width 2/4 and type int/double should be converted into an int 2 and a...
111
by: Tonio Cartonio | last post by:
I have to read characters from stdin and save them in a string. The problem is that I don't know how much characters will be read. Francesco -- ------------------------------------- ...
2
by: jimmy | last post by:
Hi, I have an XML string that has been returned using a WebRequest object that i now need extract some data from. Some sample data is shown below. <?xml version="1.0" encoding="UTF-8"?>...
7
by: random guy | last post by:
Hi, I'm writing a program which creates an index of text files. For each file it processes, the program records the start and end positions (as returned by tellg()) of sections of interest,...
3
by: waldek | last post by:
Hi, I'm using C dll with py module and wanna read value (buffer of bytes) returned in py callback as parameter passed to dll function. -------------------------------------------------- def ...
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
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...
0
jinu1996
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.