Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What is RIGHT() equivalent in C#
Message
From
21/05/2010 13:13:30
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 3.0
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01465459
Message ID:
01465475
Views:
51
The gotcha is that length is not zero based, but the other positions are. If you got that, you should be able to make it work. Trying to access a value past the end of the string or before it just throws and exception.
Tim

>I am getting the idea. Up until now, we had not worked too much with manipulation of strings. Strange that we could go 11 weeks in this C# class and not do very much in this arena. String manipulation is the bread and butter of all programming in my mind.
>
>By the way, many of my ancestors lived in east Texas, some of them coming befoe Texas was its own country. I believe that some of them may have been citizens of Spain, and then Mexico, before Texas won its independence. They came from other southern and eastern states. So, hmmm, do I put down that I am Hispanic on those job application forms? :)
>
>Here's what I've figured out with my substitution for RIGHT() in the below code:
>
>
>        private void calculateTotalCostsButton_Click(object sender, EventArgs e)
>        {
>            // Get the count of items selected by user, which is also the
>            // length of the following array.
>            int arrayLength = purchaseListBox.Items.Count;
>            string[] priceListItemsString = new string[arrayLength];
>            decimal priceListItemsDecimal = new decimal(arrayLength);
>
>            for (int i = 0; i < arrayLength; i++ )
>            {
>                // Pick up the Items from the purchaseListBox and put them into an array string.
>                priceListItemsString[i] = purchaseListBox.Items[i].ToString();
>                string oneItemString = purchaseListBox.Items[i].ToString();
>                //int lengthOfString = purchaseListBox.Items[i].ToString().Length;
>                int lengthOfString = oneItemString.Length;
>                int startPosition = oneItemString.IndexOf("$") + 1; // Go 1 position past $ sign.
>                // Get the dollar amount string without the dollar sign.
>                priceListItemsString[i] =
>                    oneItemString.Substring(startPosition, lengthOfString - startPosition);
>            }
>
>            // You now have the array string containing the dollar amounts.
>            // Send the priceListItemsString array to BusinessClass as a parameter.
>
>        }
>
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform