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

How to use indexof () in java

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use indexof () in java. It is very detailed and has a certain reference value. Friends who are interested must finish it!

IndexOf method

Returns the character position of the first occurrence of the substring in the String object.

StrObj.indexOf (subString [, startIndex])

Parameters.

StrObj

Required. String object or text.

SubString

Required. The substring to find in the String object.

StarIndex

Optional. The integer value indicates the index to start the lookup within the String object. If omitted, look at the beginning of the string.

Description

The indexOf method returns an integer value indicating the start of the substring within the String object. If no substring is found,-1 is returned.

If startindex is negative, startindex is treated as zero. If it is larger than the largest character position index, it is considered the largest possible index.

Perform a lookup from left to right. Otherwise, the method is the same as lastIndexOf.

Example

The following example illustrates the use of the indexOf method.

Function IndexDemo (str2) {

Var str1 = "BABEBIBOBUBABEBIBOBU"

Var s = str1.indexOf (str2)

Return (s)

}

The above is all the contents of the article "how to use indexof () in java". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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

Development

Wechat

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

12
Report