473,394 Members | 1,641 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,394 software developers and data experts.

Is this forum for C# as well?

Hi

I have a small problem with an array. I get given a customer code which needs to be broken in an array (no problem). Lets pretend the customer code is sweets20. I need to break it down into 2 categories. 1, sweets, 2 the number (quantity).

My code
Expand|Select|Wrap|Line Numbers
  1.  string array_PartNo = txtPartNo.Text;
  2.                     char[] array_PartNo02 = array_PartNo.ToCharArray();
  3.  
  4.                     for (int i = 0; i < array_PartNo02.Length; i++) ;
  5.                     {
  6.                         string var_food = "";
  7.                         var_food += array_PartNo02[0];
  8.                         var_food += array_PartNo02[1];
  9.                         var_food += array_PartNo02[2];
  10.                         var_food += array_PartNo02[3];
  11.                         var_food += array_PartNo02[4];
  12.                         var_food = var_food.ToUpper();
  13.  

So, it breaks the partno (sweets20) into individual characters, then it builds them up (eg, taking array 0 - 4 and turning it into a string. I can use the same method for the number of sweets with PartNo02[5] and PartNo02[06].

However, if some one ordered 100 sweets, the entire thing goes bad. I need a way of telling the program to count the last few (however long it may be)

Any ideas? I may be going totally the wrong way around this.

Thank you

Dave
Jan 29 '08 #1
1 819
nateraaaa
663 Expert 512MB
Try this code

Expand|Select|Wrap|Line Numbers
  1. string array_PartNo = "sweets100";
  2.             char[] array_PartNo02 = array_PartNo.ToCharArray();
  3.  
  4.             string var_food = "";
  5.             string amountOrdered = "";
  6.             for(int i = 0; i < array_PartNo02.Length; i++)
  7.             {
  8.                 try
  9.                 {
  10.                     int amount = Convert.ToInt32(array_PartNo02[i].ToString());
  11.                     amountOrdered += amount.ToString();
  12.                 }
  13.                 catch
  14.                 {
  15.                     //Not a number
  16.                     var_food += array_PartNo02[i].ToString();
  17.                 }
  18.             }
  19.  
  20.             Response.Write(var_food + "<br>" + amountOrdered);
Nathan
Jan 29 '08 #2

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

Similar topics

18
by: Jonas Melian | last post by:
Hi, I'm going to say a suggestion, why don't you create a forum like the one of Ruby (http://www.rubyforums.com/)? for the novices this is a great help, better than a mail list It's also...
31
by: pamelafluente | last post by:
Dear guys, I hope not to be intrusive. I just want to inform you, in case someone cares, about a new forum, where Questions or Announcements on topics relevant to this newsgroup can be freely...
8
by: Jeff | last post by:
I am in the process of writing my own forum. It is gone fairly well so far. I been searching different forum scripts, both asp and php, and I can't find this answer. How is it scripted to only...
13
by: Joni Nieminen | last post by:
Is there any code or script which do forum in the page! I can do little javascript.. Help?!
4
by: GaryDean | last post by:
Is there a forum somewhere specializing in WSE 3.0? I am going through the "Microsoft Web Service Security Patterns and Practices" book/pdf and it has a link to a community forum with a url of...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...

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.