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

Get last two characters of a string

RP
I store current year in string format. I want to get the last two
values of the year. For example: if year is 2007, I want 07.

Which string function to use ?

Nov 12 '07 #1
3 91511
On Nov 12, 12:55 pm, RP <rpk.gene...@gmail.comwrote:
I store current year in string format. I want to get the last two
values of the year. For example: if year is 2007, I want 07.

Which string function to use ?
Use Substring and the Length property:

string lastTwoChars = original.Substring (original.Length-2);

Jon

Nov 12 '07 #2
On Nov 12, 1:03 pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Nov 12, 12:55 pm, RP <rpk.gene...@gmail.comwrote:
I store current year in string format. I want to get the last two
values of the year. For example: if year is 2007, I want 07.
Which string function to use ?

Use Substring and the Length property:

string lastTwoChars = original.Substring (original.Length-2);

Jon
In this case, it may be important to mention that you can do:
date.ToString("yy");

to get directly the wanted result.

Kind regards.
Anthony

Nov 12 '07 #3
BlueTrin wrote:
>>I store current year in string format. I want to get the last two
values of the year. For example: if year is 2007, I want 07.
Which string function to use ?
Use Substring and the Length property:

string lastTwoChars = original.Substring (original.Length-2);

Jon

In this case, it may be important to mention that you can do:
date.ToString("yy");

to get directly the wanted result.
Only if the value is a DateTime, while the OP indicated he was storing
the Year as a string.

Chris.
Nov 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Tihon | last post by:
Hello everyone! I've got the problem with string replace, i've got a string like: /adsf/sdfd34/sdf/435ff/sdfdf and i need to delete the last characters before "/", so it would become:...
5
by: oliver | last post by:
hi there i'm experimanting with imaplib and came across stringts like (\HasNoChildren) "." "INBOX.Sent Items" in which the quotes are part of the string. now i try to convert this into a...
5
by: Wade G. Pemberton | last post by:
Can't find it quickly in the reference books.
8
by: DrBob | last post by:
gcc 3.3 MAC OS X. I have a string that has trailing spaces in it that I want removed. So i have a variable: string x("abcd "); x.trim() isn't an implemented method. Is there a method I...
0
by: Fuochi | last post by:
hello, I have Visual Studio .Net 2002 C++. I have migrated a code created under VS 6.0 that contains a call to the method CreateField. This method fail in release mode if the string parameter...
6
by: kbarz | last post by:
Hi, I have a VB.Net program that extracts data from Word document tables and saves it off to Sql Server. I notice that when it gets to the database, there are two nonprintable characters on the...
11
by: drtimhill | last post by:
I'm just starting out on Python, and am stumped by what appears an oddity in the way negative indices are handled. For example, to get the last character in a string, I can enter "x". To get the...
8
by: gthorpe | last post by:
Hi, I have a question about string constants. I compile the following program: #include <stdio.h> #include <string.h> int main(void) { char str1 = "\007";
9
by: Alan | last post by:
I am kind of new to javascript, I am not sure if there is direct support for "tokens" in the sense that they are characters that mark places in a string. For example if I had var mystring =...
11
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.