473,545 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
+ 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 2142
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,i nt) 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
2343
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: value = document.form1.lblMyLabelControl.innerText; but, innerText property is not compatibile with W3 DOM, so mozilla doesn't support this.
1
2445
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 again</child2> </parent> <aunt> <cousin1>text</cousin1>
0
1167
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 again</child2> </parent> <aunt> <cousin1>text</cousin1>
2
1911
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 the leading length byte. In my "real" project I have the following code. The first MessageBox tells me that the stream position is correct for...
1
969
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
1830
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 double 3.45. Here is my code: #include <iostream> #include <string> typedef unsigned ResultT;
111
19934
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 -- ------------------------------------- http://www.riscossione.info/
2
1454
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"?> <ISBNdb server_time="2005-02-25T23:03:41"> <BookList total_results="1" page_size="10" page_number="1" shown_results="1">
7
3051
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, and then some time later uses these positions to read the interesting sections from the file.
3
4388
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 mycallback(data, size): # how to read data buffer here ? return 0
0
7470
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, 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...
1
7428
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...
0
5975
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4949
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...
0
3455
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1887
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 we have to send another system
1
1019
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
709
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.