473,585 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 91550
On Nov 12, 12:55 pm, RP <rpk.gene...@gm ail.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.Substr ing (original.Lengt h-2);

Jon

Nov 12 '07 #2
On Nov 12, 1:03 pm, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
On Nov 12, 12:55 pm, RP <rpk.gene...@gm ail.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.Substr ing (original.Lengt h-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.Substr ing (original.Lengt h-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
2763
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: /adsf/sdfd34/sdf/435ff/ I am trying to make a file manager of a sort, and need to make a link "UP", which would take the user up one level in a directory......
5
3264
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 list. assume the string is in the variable f, then i tried f.split() but i end up with
5
129013
by: Wade G. Pemberton | last post by:
Can't find it quickly in the reference books.
8
17720
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 don't know about? What do I do to extent the string class such that there is a method to
0
1107
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 contains exactly 8 characters, but not in debug mode. does anyone know if it exists a patch for VS .Net IDE
6
1715
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 end of each field. I thought of using substring-before to parse these out, but I'm not sure how to refer to them as they are just represented as...
11
3718
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 2nd and 3rd to last, I can enter x etc. This is fine. Logically, I should be able to enter x to get the last and next to last characters. However,...
8
3098
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
15996
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 = "12345:abcde"; and I wanted to consider the colon ":" in the middle a token, how would I define a new variable that is everything that comes before...
11
3047
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 spaces, but not in the inner string(\"and a inner string\\\"). Will anyone please tell me how to do this?
0
7908
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7950
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.