Split string with multiple characters using C# and VB.Net in ASP.Net

Corobori
 
on Aug 24, 2020 12:03 AM
Sample_168988.zip
1927 Views

Hi,

I need to split this string into an array: 17615.3_999999#sin- 

What I need is 

p(0) = 17615

p(1) = 3

p(2) = 999999

p(3) = sin

So far I am with the code shown below which gets me this

p(0) = 17615

p(1) = 3_999999#sin

Dim splitAtPipe = vOpciones.Split("-"c)
Dim result = splitAtPipe.Select(Function(x) x.Split("."c)).ToArray()
Dim p() As String
Dim iIdx As Integer = 0
For iIdx = 0 To result.Length - 1
       p = result(iIdx)
 Next

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Aug 24, 2020 01:03 AM

Hi Corobori,

Use below code.

C#

protected void Page_Load(object sender, EventArgs e)
{
    string vOpciones = "17615.3_999999#sin-";
    string splitAtPipe = vOpciones.Split('-')[0];
    char[] characters = { '.', '_', '#' };
    string[] p = splitAtPipe.Split(characters, StringSplitOptions.RemoveEmptyEntries);
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim vOpciones As String = "17615.3_999999#sin-"
    Dim splitAtPipe As String = vOpciones.Split("-"c)(0)
    Dim characters As Char() = {"."c, "_"c, "#"c}
    Dim p As String() = splitAtPipe.Split(characters, StringSplitOptions.RemoveEmptyEntries)
End Sub

Screenshot