简体   繁体   中英

VB.NET Skip characters

I'm using a wildcard on a string. and then i put the result on another string.

dim Wild1 as string = "ab Ab AB ?? ?? ??"
dim Wild2 as string = "ba Ba BA ?? ?? ??"

dim result1 as string = searcher(wild1)
dim result2 as string = searcher(wild2)

now, the problem here is that i want to replace the whatever 3 last digits that were found on result1 to whatever 3 last digits that were found in result 2

so i want my program to count the length. or skip the first digits

To get the last three characters, you can use a substring:

Dim text As String = "ABC DEF GHI"
Dim last3 As String = text.Substring(text.Length - 3, 3)

last3 , in this example, equals GHI .

Then, if you need to replace part of another string with last3 :

Dim text2 As String = "JKL MNO PQR"
text2 = text2.Remove(text2.Length - 3, 3) & last3

This then gives you, for text2 , JKL MNO GHI .

(I am not sure if this is what you needed because your question is a bit unclear.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM