473,407 Members | 2,326 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,407 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 91515
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.