Solved

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

Posted on 2011-09-21
1
223 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
ID: 36575187
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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