如何提取字符串的一部分并将其存储为arraylist? [英] How do I extract a portion of the string and store it an arraylist?

查看:116
本文介绍了如何提取字符串的一部分并将其存储为arraylist?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨:

我有一个文件数组,其中包含以下格式的字符串:



abc12345.xxx_xxx001.001045



以上述格式存储的字符串可以帮助我完成部分工作



现在,存储了这个,我想提取该字符串的一部分并将其存储为数组



如何从该字符串中单独提取abc12345并将其存储为数组? />


我尝试了什么:



我尝试使用split命令。我面临的问题是:

PN(0)店铺abc12345

PN(1)店铺xxx_xx001

PN(2)店铺001045

我希望abc12345存储为PN(0),下一个后续部件号存储为PN(1)

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)

Dim PN As New ArrayList()
For Each element In file1array
    PN = element.split("."c)

Next

推荐答案

我想你想要的是:

I think what you want is like:
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



你必须分别将 Split 结果添加到 ArrayList


这篇关于如何提取字符串的一部分并将其存储为arraylist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆