473,473 Members | 2,005 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 2137
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 ...
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
Oralloy
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,...
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
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
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 ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.