Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of searching and replacing python string

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "the method of python string search and replacement". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "the method of python string search and replacement" can help you solve the problem.

Find

Instr (parameter 1, parameter 2, parameter 3, parameter 4)

Parameter 1: search from left to right by default. This parameter indicates the location where the search starts. The default is 1.

Parameter 2: represents the source string

Parameter 3: represents the string to find

Parameter 4: represents the way to find it, here we use vbbinarycompare

Vbbinarycompare returns the location found by the string, and returns 0 if it is not found

The selection function of Textbox control

Text1.SetFocus' set focus

Text1.SelStart = pos-1 'Note this is where the cursor starts

Text1.SelLength = Len (Text2.Text) 'Select a few characters back from the cursor

Replace function

Replacement function

Replace (source string, string to find, which string to replace)

Return result: return the string after the source string has been replaced

Software design interface:

Source code sharing:

Private Sub Command1_Click (Index As Integer) 'Note If Command1 (Index). Caption = "find" Then Dim pos& pos = InStr (1, Text1.Text, Text2.Text, vbBinaryCompare) Text1.SetFocus' set focus Text1.SelStart = pos-1 Text1.SelLength = Len (Text2.Text) ElseIf Command1 (Index). Caption = "replace" Then Text1.Text = Replace (Text1.Text, Text2.Text, Text3.Text)

End If

End Sub

This is the end of the introduction to "the method of finding and replacing python strings". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report