DreamKid Posted August 1, 2005 Posted August 1, 2005 I need to convert a String to Integer. The String consists of: 3 23 5 7 4 8 10 12 I would like to store each Number in the String into an array of Integers. Each Integer is seperate by a space. Any idea how can I do that? Thanks in advance. Quote
Administrators PlausiblyDamp Posted August 1, 2005 Administrators Posted August 1, 2005 private int[] StringToIntegerArray(string numbers) { string[] nums = numbers.Split(' '); int[] ints = new int[nums.Length]; for (int i=0;i ints[i] = int.Parse(nums[i]); return ints; } should get you started - you will need to provide some error checking to validate the initial string etc though. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Himo Posted August 1, 2005 Posted August 1, 2005 Other ways are: Using the Convert class en typecasting (using (int)StringS ) Quote For questions about VS .net extensibility, please fire at me! :) For readability, please use the [ CS][/CS ] tags
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.