Share vb.net instr

Chức năng VB.NET Ứng dụng: Nhận vị trí của chuỗi trong chuỗi khác

Hàm VB.NET Ứng dụng trả về vị trí của một chuỗi con được chỉ định trong một chuỗi.Cú pháp của chức năng INST như sau:

`` `
INST (String1, String2, Start, So sánh)
`` `

*** String1 ** là chuỗi để tìm kiếm.
*** String2 ** là phần phụ để tìm kiếm.
*** Bắt đầu ** là vị trí bắt đầu trong String1 để bắt đầu tìm kiếm.
*** So sánh ** là tùy chọn so sánh để sử dụng.Giá trị mặc định là 0, có nghĩa là so sánh nhạy cảm trường hợp.

Hàm uster trả về các giá trị sau:

* -1 nếu không tìm thấy chuỗi con trong String1.
* Vị trí của lần xuất hiện đầu tiên của chuỗi con trong String1, bắt đầu ở vị trí bắt đầu được chỉ định.

Ví dụ: mã sau sử dụng chức năng INTS để tìm vị trí của từ "" trong chuỗi ", con cáo màu nâu nhanh nhảy qua con chó lười":

`` `
Dim Str1 như String = "Con cáo màu nâu nhanh chóng nhảy qua con chó lười biếng"
Dim str2 dưới dạng chuỗi = "The"
Dim Start As Integer = 0
So sánh dim là số nguyên = 0

Chỉ số Dim dưới dạng Integer = orch (str1, str2, start, so sánh)

Nếu chỉ mục <0 thì
Console.WriteLine ("Không tìm thấy chuỗi con.")
Khác
Console.WriteLine ("Subring được tìm thấy tại vị trí {0}.", Index)
Kết thúc nếu
`` `

Mã này sẽ xuất ra như sau:

`` `
Các nền tảng được tìm thấy ở vị trí 2.
`` `

## Người giới thiệu

* [Chức năng VB.NET Ứng dụng] (https://docs.microsoft.com/en-us/dotnet/api/system.string.instr)
* [So sánh chuỗi vb.net] (String.Compare Method (System))

## hashtags

* #vb.net
* #dây
* #chức năng
* #Comparison
* #Programming
=======================================
VB.NET Instr Function: Get the Position of a String in Another String

The VB.NET Instr function returns the position of a specified substring within a string. The syntax of the Instr function is as follows:

```
Instr(string1, string2, start, compare)
```

* **string1** is the string to search in.
* **string2** is the substring to search for.
* **start** is the starting position in string1 to start the search.
* **compare** is the comparison option to use. The default value is 0, which means a case-sensitive comparison.

The Instr function returns the following values:

* -1 if the substring is not found in string1.
* The position of the first occurrence of the substring in string1, starting at the specified start position.

For example, the following code uses the Instr function to find the position of the word "the" in the string "the quick brown fox jumps over the lazy dog":

```
Dim str1 As String = "the quick brown fox jumps over the lazy dog"
Dim str2 As String = "the"
Dim start As Integer = 0
Dim compare As Integer = 0

Dim index As Integer = Instr(str1, str2, start, compare)

If index < 0 Then
Console.WriteLine("The substring was not found.")
Else
Console.WriteLine("The substring was found at position {0}.", index)
End If
```

This code will output the following:

```
The substring was found at position 2.
```

## References

* [VB.NET Instr Function](https://docs.microsoft.com/en-us/dotnet/api/system.string.instr)
* [VB.NET String Comparison](https://docs.microsoft.com/en-us/dotnet/api/system.string.compare)

## Hashtags

* #vb.net
* #strings
* #Functions
* #Comparison
* #Programming
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top