Click here to Skip to main content
15,994,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi:
I have a file array which carries strings in the following format:

"abc12345.xxx_xxx001.001045"

The string stored in above format helps me do a portion of my job

Now, having stored this, I want to extract a portion of this string and store it an array

How do I extract "abc12345" alone from this string and store it an array?

What I have tried:

I tried using the split command. The problem am facing is:
PN(0) stores abc12345
PN(1) stores xxx_xx001
PN(2) stores 001045
I want abc12345 to be stored as PN(0) and next subsequent part number to be stored as PN(1)
VB
Dim PN As New ArrayList()
For Each element In file1array
    PN = element.split("."c)

Next
Posted
Updated 17-May-16 15:04pm
v2
Comments
Sergey Alexandrovich Kryukov 17-May-16 20:22pm    
Not clear. Can you describe formal general-case format? what should be instead of those xx?
If you only need digits, remove all non-digits. What the problem? There is more general Split, there is Trim, and there is Regex.
—SA
Member 12471735 17-May-16 20:56pm    
All x's represent alphabets

1 solution

I think what you want is like:
VB
Dim PN As New ArrayList()
Dim splitElement as String() = Nothing
For Each element In file1array
    splitElement = element.Split("."c, 1) ' you only want one anyway
    PN.Add(splitElement(0))
Next

You have to add each Split result to the ArrayList separately.
 
Share this answer
 
Comments
Member 12471735 17-May-16 22:25pm    
Thanks for your help. Got following error
An unhandled exception of type 'System.Reflection.AmbiguousMatchException' occurred in Microsoft.VisualBasic.dll

Additional information: Overload resolution failed because no Public 'Split' can be called with these arguments:

'Public Function Split(ParamArray separator As Char()) As String()':

Argument matching parameter 'separator' cannot convert from 'Integer' to 'Char'.

'Public Function Split(separator As Char(), count As Integer) As String()':

Argument matching parameter 'separator' cannot convert from 'Char' to 'Char()'.

'Public Function Split(separator As Char(), options As System.StringSplitOptions) As String()':

Argument matching parameter 'separator' cannot convert from 'Char' to 'Char()'.

'Public Function Split(separator As String(), options As System.StringSplitOptions) As String()':

Argument matching parameter 'separator' cannot convert from 'Char' to 'String()'.
Member 12471735 17-May-16 22:59pm    
Made it work
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900