473,379 Members | 1,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Parse string to integer C#

210 Expert 100+
I have a page set where i get data in following format

41128°°8/20/2007 12:00:00 AM°11:00°True

These data are stored in an arraylist name d. Then i use following code to split the data

Expand|Select|Wrap|Line Numbers
  1.  
  2.  ArrayList d = new ArrayList();
  3.         d = x.GetDataList();  //x is a class ; GetDataList returns data as Arraylist
  4.  
  5.  //manipulating data
  6.             string data = d[0].ToString();
  7.             char deli = '°';
  8.             string[] load = data.Split(deli);
  9.  
  10.             string shid = load[0].ToString();
  11.             string pnum = load[1].ToString();
  12.             string pdate = load[2].ToString();
  13.             string ptime = load[3].ToString();
  14.             string pfcfs = load[4].ToString();
  15.  
  16.  
when i display the data string shid i get the value 41128. But when i try to use Int32.Parse to convert the value to an integer i get an error Input string was not in correct format. The code is

Expand|Select|Wrap|Line Numbers
  1. lblerr.Text = Int32.Parse(shid);
  2.  
After getting the input string error. I used .Trim() removing any form of spaces but still i get the same error. Please advice.
Sep 30 '08 #1
2 1884
Plater
7,872 Expert 4TB
Have you used the debugger to examine exactly what is in the string?
Then making sure the .Length property of the string is not longer then it should be?
For your example "41128" should have a .Length of 5
Sep 30 '08 #2
semomaniz
210 Expert 100+
I got the problem solved. When i used the . Length method i got the value 9 rather than 5. The i changed the delimiter from '°' to '^' and got the data as following format

41128^^8/20/2007 12:00:00 AM^11:00^True

All the code work perfectly. I am assuming '°' (ctrl + 248) some how added extra length to the string.

Thank you
Sep 30 '08 #3

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

Similar topics

3
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need...
9
by: Danny | last post by:
HI again Is there a nifty function in access that will: 1. return the amount of occurances of a small string within a larger string? this<br>is<br>a<br>test would return 3 for <br>
15
by: Brian Henry | last post by:
Which one is better to use? CInt(string) or Integer.Parse(string)? thanks!
16
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array...
15
by: Teresa | last post by:
1) Should I use Integer.Parse to convert a string into an integer in .NET now? CType(sUserID, Integer) OR Integer.Parse(sUserID) 2) And is it better to use the string class to trim, get length,...
7
by: Joe | last post by:
Hello All: Does anyone know the difference between CType(x,Integer) vs. Integer.Parse(x)? Is there a performance advantage to one or the other? TIA, -- Joe
5
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML...
10
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from...
29
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
4
by: Peter Proost | last post by:
Hi group, it's been a long time since the last time I've been here but I have a question. I'm working with timespan.parse for calculating a duration, I have to add strings which are in the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.