首頁 後端開發 php教程 php傳回在字串中查找到任何指定的字元之前的字元數函數strcspn()

php傳回在字串中查找到任何指定的字元之前的字元數函數strcspn()

Nov 04, 2017 am 09:51 AM
php 字串

實例

輸出在字串 "Hello world!" 中找到字元"w" 之前尋找的字元數:

<?php
echo strcspn("Hello world!","w");
?>
登入後複製

定義和用法

strcspn() 函數傳回在找到任何指定的字元之前,在字串中尋找的字元數(包括空格)。

提示: Use the strspn() function to the number of characters found in the string that contains only characters from a specified character list.

註解: This function is binary-safe.

語法

strcspn(string,char,start,length)
登入後複製
參數描述
string必要。規定要搜尋的字串。
char必要。規定要找的字元。
start可選。規定開始尋找的位置。
length可選。規定字串的長度(搜尋多少字元)。

更多實例

實例1

#使用所有的參數來輸出在字串"Hello world!" 中找到字元" w" 先前尋找的字元數:

<?php
echo strcspn("Hello world!","w",0,6); // The start position is 0 and the length of the search string is 6.
?>
登入後複製

函數功能:以str1為參照,比較字串str2中的字元是否與str中某個字元相等(也就是檢索str2中的字元是否在str1中存在),如果第一次發現相等,則停止並傳回在str1中這個符合相等的字元的索引值,失敗則傳回str1的長度。
  
回傳說明:傳回在str1中這個符合相等的字元的索引值,是一個整數值。

其它說明:暫時無。

實例:

#include <string.h>
#include <stdio.h>
int main()
{
    char *str1="aaaaakkkeeee";  
    char *str2="John,he like writing!"; 

    int inttemp;

    inttemp=strcspn(str1,str2);   //将str2中的每个字符均与str1中的匹配,如果这个字符在str1中出现过,则返回这个字符在str1中的索引值
     printf("The first index of the character both in str1 and str2: %d  ", inttemp);
    return 0;
}
登入後複製

在VC++ 6.0編譯執行:

php傳回在字串中查找到任何指定的字元之前的字元數函數strcspn()

以上是php傳回在字串中查找到任何指定的字元之前的字元數函數strcspn()的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章標籤

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南 適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南 Dec 24, 2024 pm 04:42 PM

適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南

CakePHP 專案配置 CakePHP 專案配置 Sep 10, 2024 pm 05:25 PM

CakePHP 專案配置

CakePHP 日期和時間 CakePHP 日期和時間 Sep 10, 2024 pm 05:27 PM

CakePHP 日期和時間

CakePHP 檔案上傳 CakePHP 檔案上傳 Sep 10, 2024 pm 05:27 PM

CakePHP 檔案上傳

CakePHP 路由 CakePHP 路由 Sep 10, 2024 pm 05:25 PM

CakePHP 路由

討論 CakePHP 討論 CakePHP Sep 10, 2024 pm 05:28 PM

討論 CakePHP

如何設定 Visual Studio Code (VS Code) 進行 PHP 開發 如何設定 Visual Studio Code (VS Code) 進行 PHP 開發 Dec 20, 2024 am 11:31 AM

如何設定 Visual Studio Code (VS Code) 進行 PHP 開發

CakePHP 快速指南 CakePHP 快速指南 Sep 10, 2024 pm 05:27 PM

CakePHP 快速指南

See all articles