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

extract after second _

Hi,
I have this string 111_XYZ11_2345, 22_zz22_33, .., How can I extract only
last numbers like 2345 and 33.
Thanks,
Jim.

Jul 21 '05 #1
3 1362

Hi,
I used this one, do you see any problem with this?
lastDashPos = fName.LastIndexOf("_") + 1
LastNumStr = Microsoft.VisualBasic.Right(fName, Len(fName) -
lastDashPos)

Thanks,
Jim.

"JIM.H." wrote:
Hi,
I have this string 111_XYZ11_2345, 22_zz22_33, .., How can I extract only
last numbers like 2345 and 33.
Thanks,
Jim.

Jul 21 '05 #2
JIM.H. <JI**@discussions.microsoft.com> wrote:
I have this string 111_XYZ11_2345, 22_zz22_33, .., How can I extract only
last numbers like 2345 and 33.


Are you asking for "everything after the last _" or "everything after
the second _"? It makes a difference when you've got more than 2 _
characters in the input string :)

To get everything after the second _, use String.IndexOf twice,
starting the search after the first _ to find the second _. Then use
String.Substring.

To get everything after the last _, use String.LastIndexOf, and then
use String.Substring.

In each case, you should check the result of String.IndexOf - if it's
-1, the _ character wasn't found.

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

I do not see your code as a problem, however it does not look nice with
those two namespaces mixed up.
\\\
lastDashPos = fName.LastIndexOf("_")
LastNumStr = fName.SubString(lastDashPosh + 1)
///
I find this looks nicer.

It can even be just as you wish
\\\
LastNumStr = fName.SubString(fName.LastIndexOf("_") +1)
///

Did you know that there is a special and very active newsgroup for VBNet
language questions?

Microsoft.public.dotnet.languages.vb

I hope this helps?

Cor
Jul 21 '05 #4

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

Similar topics

11
by: Ren | last post by:
Suppose I have a file containing several lines similar to this: :10000000E7280530AC00A530AD00AD0B0528AC0BE2 The data I want to extract are 8 hexadecimal strings, the first of which is E728,...
7
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For...
2
by: sam | last post by:
HI, I want to know what the key is in a hash_map object. eg. myhash = "value"; How can I extract the "key_name" from myhash? Thanks Sam
9
by: Sharon | last post by:
hi, I want to extract a string from a file, if the file is like this: 1 This is the string 2 3 4 how could I extract the string, starting from the 10th position (i.e. "T") and...
3
by: JIM.H. | last post by:
Hi, I have this string 111_XYZ11_2345, 22_zz22_33, .., How can I extract only last numbers like 2345 and 33. Thanks, Jim.
5
by: Jim Carlock | last post by:
I'm looking to use an image of letters and numbers, whereby I need a way to extract each letter and number to create random strings, then combine/conjoin/meld/mesh/merge/unify/unite the images...
0
by: napolpie | last post by:
DISCUSSION IN USER nappie writes: Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by...
5
by: =?Utf-8?B?aWxy?= | last post by:
Hi This is probably fairly simple but I am newish at programming and was wondering if someone can give me some advice on handling the following. I have an array with a large number of elements...
1
by: charvi | last post by:
Hi i am doing a project in vb6 and ms access i have a name like John Smith i want to extract Js from this that is first letter from first namw and second letter from second name pls help
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...
0
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...

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.