Solved

How to read the rightmost 8 positions into a string using a C# console application?

Posted on 2011-09-21
1
221 Views
Last Modified: 2013-12-17
I am developing a C# Console application using Visual Studio 2005.

My code follows in the code section.

How could I change the code and replace the following statement:
String formattedString = itemsequence.Substring(7, 8);

with another statement that assigns the rightmost 8 positions to formattedString, since I am checking for a field length of at least 8 positions and I want to assign just the right most positions.
if (reader.Name.Length >= 8)
                            {
                                arr1[i, 11] = "GROUP_FIELD_NAME:CpcsNo";
                                itemsequence = reader.ReadElementContentAsString();
                                String formattedString = itemsequence.Substring(7, 8);

Open in new window

0
Comment
Question by:zimmer9
1 Comment
 
LVL 8

Accepted Solution

by:
gena17 earned 500 total points
Comment Utility
Like this:
itemsequence.Substring(itemsequence.Length-8)
Of course you need to check that there are at least 8 chars in advance.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now