Click here to Skip to main content
15,905,233 members
Home / Discussions / C#
   

C#

 
GeneralRe: Fast string to integer conversion Pin
HosamAly6-Jan-09 22:29
HosamAly6-Jan-09 22:29 
GeneralRe: Fast string to integer conversion Pin
J4amieC6-Jan-09 23:08
J4amieC6-Jan-09 23:08 
GeneralRe: Fast string to integer conversion Pin
HosamAly6-Jan-09 23:15
HosamAly6-Jan-09 23:15 
GeneralRe: Fast string to integer conversion Pin
J4amieC6-Jan-09 23:54
J4amieC6-Jan-09 23:54 
AnswerRe: Fast string to integer conversion Pin
Dragonfly_Lee6-Jan-09 22:14
Dragonfly_Lee6-Jan-09 22:14 
GeneralRe: Fast string to integer conversion Pin
HosamAly6-Jan-09 22:27
HosamAly6-Jan-09 22:27 
GeneralRe: Fast string to integer conversion Pin
Dragonfly_Lee6-Jan-09 22:42
Dragonfly_Lee6-Jan-09 22:42 
AnswerRe: Fast string to integer conversion Pin
Guffa6-Jan-09 23:49
Guffa6-Jan-09 23:49 
Parsing a string is not very hard. I put together this code, it should cover the basics:

public static int ParseInt32(string text) {
	long value = 0;
	long sign = 1;
	bool first = true;
	foreach (char c in text) {
		if (c >= '0' && c <= '9') {
			value = value * 10 + c - '0';
		} else if (c == '-' && first) {
			sign = -1;
 		} else {
			throw new FormatException();
		}
		first = false;
	}
	value *= sign;
	if (value < int.MinValue || value > int.MaxValue) throw new OverflowException();
	return (int)value;
}


Despite everything, the person most likely to be fooling you next is yourself.

GeneralRe: Fast string to integer conversion Pin
N a v a n e e t h7-Jan-09 0:04
N a v a n e e t h7-Jan-09 0:04 
GeneralRe: Fast string to integer conversion Pin
Le centriste7-Jan-09 1:13
Le centriste7-Jan-09 1:13 
GeneralRe: Fast string to integer conversion Pin
HosamAly7-Jan-09 8:59
HosamAly7-Jan-09 8:59 
GeneralRe: Fast string to integer conversion Pin
Le centriste7-Jan-09 9:16
Le centriste7-Jan-09 9:16 
GeneralRe: Fast string to integer conversion Pin
Guffa7-Jan-09 2:46
Guffa7-Jan-09 2:46 
GeneralRe: Fast string to integer conversion Pin
HosamAly7-Jan-09 8:31
HosamAly7-Jan-09 8:31 
QuestionCalling C# Managed code in VB Pin
satsumatable6-Jan-09 19:47
satsumatable6-Jan-09 19:47 
AnswerRe: Calling C# Managed code in VB Pin
Mycroft Holmes6-Jan-09 20:31
professionalMycroft Holmes6-Jan-09 20:31 
AnswerRe: Calling C# Managed code in VB Pin
Spoon656-Jan-09 22:25
Spoon656-Jan-09 22:25 
AnswerRe: Calling C# Managed code in VB Pin
Dragonfly_Lee6-Jan-09 22:50
Dragonfly_Lee6-Jan-09 22:50 
AnswerRe: Calling C# Managed code in VB Pin
Jason C Bourne7-Jan-09 11:12
Jason C Bourne7-Jan-09 11:12 
Questionreturn 0? Pin
dec826-Jan-09 19:29
dec826-Jan-09 19:29 
AnswerRe: return 0? Pin
mav.northwind6-Jan-09 19:59
mav.northwind6-Jan-09 19:59 
AnswerRe: return 0? Pin
rah_sin6-Jan-09 20:03
professionalrah_sin6-Jan-09 20:03 
AnswerRe: return 0? Pin
«_Superman_»6-Jan-09 21:06
professional«_Superman_»6-Jan-09 21:06 
AnswerRe: return 0? Pin
CPallini6-Jan-09 22:16
mveCPallini6-Jan-09 22:16 
AnswerRe: return 0? Pin
Dragonfly_Lee6-Jan-09 22:52
Dragonfly_Lee6-Jan-09 22:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.