473,398 Members | 2,368 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,398 software developers and data experts.

string method

How do you detect a string's right 3 charaters, say
string "abcde". I'd like to detect if the right three
charaters are "cde", then proceeding doing something.
Anyone know which method shall I use? Thanx.
Jul 19 '05 #1
5 2540
Using VB.NET
---------------
Dim myString As String = "Hello World!"
Dim subString As String
subString = Microsoft.VisualBasic.Right(myString, 6) '
Returns "World!"
-----Original Message-----
How do you detect a string's right 3 charaters, say
string "abcde". I'd like to detect if the right three
charaters are "cde", then proceeding doing something.
Anyone know which method shall I use? Thanx.
.

Jul 19 '05 #2
Since we're talking .Net here, try String.EndsWith(string)
"July" <ba********@aol.com> wrote in message
news:07****************************@phx.gbl...
How do you detect a string's right 3 charaters, say
string "abcde". I'd like to detect if the right three
charaters are "cde", then proceeding doing something.
Anyone know which method shall I use? Thanx.

Jul 19 '05 #3
SR
Hi

Given the fact that
a) VB.Net is completel;y objectoriented
b) Microsoft.Visualbasic namespace is given for backward
compatibility

suggest that u use the String Object props/methods like
length, substring instead of Functions like Right()

The following code sniper will do wat u want.
Watch for Line wraps

Right("abcde", 3) ' Will Return "cde"

Sub Right(ByVal p_strData As String, ByVal
p_intNoOfCharsToGet As Integer)
If Not p_strData Is Nothing AndAlso
p_strData.Length >= p_intNoOfCharsToGet Then
Console.WriteLine(p_strData.Substring
((p_strData.Length - p_intNoOfCharsToGet),
p_intNoOfCharsToGet))
End If
End Sub

regards,

sr

-----Original Message-----
Using VB.NET
---------------
Dim myString As String = "Hello World!"
Dim subString As String
subString = Microsoft.VisualBasic.Right(myString, 6) '
Returns "World!"
-----Original Message-----
How do you detect a string's right 3 charaters, say
string "abcde". I'd like to detect if the right three
charaters are "cde", then proceeding doing something.
Anyone know which method shall I use? Thanx.
.

.

Jul 19 '05 #4
Keith Patrick <ri*******************@nospam.hotmail.com> wrote:
Since we're talking .Net here, try String.EndsWith(string)


Doh! That'll teach me to not bother looking at the MSDN to see whether
there's a better way than using primitive tools such as Length, IndexOf
and Substring :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #5
gt
try regular expressions
they can find just about anything and return the "other"
stuff as well
lots of examples

-----Original Message-----
July <ba********@aol.com> wrote:
How do you detect a string's right 3 charaters, say
string "abcde". I'd like to detect if the right three
charaters are "cde", then proceeding doing something.
Anyone know which method shall I use? Thanx.
Use a combination of Substring and Length to get the

right 3characters, or (slightly more efficiently) use IndexOf and specify theposition to start looking as three characters from the end of thestring.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
.

Jul 19 '05 #6

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

Similar topics

2
by: Fuzzyman | last post by:
I recently went through a bit of a headache trying to subclass string.... This is because the string is immutable and uses the mysterious __new__ method rather than __init__ to 'create' a string....
15
by: Andrew Brampton | last post by:
Hi, I'm new to using std classes, but I was wondering how I could do the following efficiently with the string class: Say I had a string with delimited values such as:...
8
by: Grant Wagner | last post by:
I'm a bit confused by String() (typeof 'string') vs new String() (typeof 'object'). When you need to access a method or property of a -String-, what type is JavaScript expecting (or rather, what...
8
by: A.M | last post by:
Hi, Are string parameters in functions by refrence or by value ? Thanks, Ali
8
by: johnsto | last post by:
I'm really stuck - can someone help me! I've got a basic setup consisting of two things: 1. A C# web service 2. An unmanaged C++ DLL The WS is intended to call some functions in the DLL. The...
35
by: Cor | last post by:
Hallo, I have promised Jay B yesterday to do some tests. The subject was a string evaluation that Jon had send in. Jay B was in doubt what was better because there was a discussion in the C#...
8
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to...
17
by: AMP | last post by:
Hello I get 2 errors in the following code that I cant Debug without some help. They are both in the TryParse function. Seems simple enough.The Errors are Below. private void...
21
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
8
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
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: 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:
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
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,...

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.