Solved

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

Posted on 2011-09-21
1
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Windows Form Navigation - Total Beginner 9 88
c#, case, if 4 34
Shared Service Environment 2 49
Call to SQL server times out 5 47
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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