一区二区三区三上|欧美在线视频五区|国产午夜无码在线观看视频|亚洲国产裸体网站|无码成年人影视|亚洲AV亚洲AV|成人开心激情五月|欧美性爱内射视频|超碰人人干人人上|一区二区无码三区亚洲人区久久精品

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

OpenHarmony語言基礎(chǔ)類庫【@ohos.uri (URI字符串解析)】

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-04-24 21:40 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

本模塊提供URI字符串解析的相關(guān)功能。

說明:

本模塊首批接口從API version 8開始支持。后續(xù)版本的新增接口,采用上角標(biāo)單獨(dú)標(biāo)記接口的起始版本。

導(dǎo)入模塊

import uri from '@ohos.uri'

URI

屬性

系統(tǒng)能力: SystemCapability.Utils.Lang

名稱類型可讀可寫說明
schemestring獲取URI 的協(xié)議部分。
userInfostring獲取 URI 的用戶信息部分。
hoststring獲取 URI 的主機(jī)名部分(不帶端口)。
portstring獲取 URI 的端口部分。
pathstring獲取 URI 的路徑部分。
querystring獲取 URI 的查詢部分。
fragmentstring獲取 URI 的片段部分
authoritystring獲取此URI的解碼權(quán)限組件部分。
sspstring獲取URI的解碼方案特定部分。

鴻蒙開發(fā)指導(dǎo)文檔:[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]

搜狗高速瀏覽器截圖20240326151450.png

命名規(guī)則

命名形式:

標(biāo)準(zhǔn)uri定義由以下三個(gè)部分組成 [scheme:]scheme-specific-part[#fragment]

  • scheme: 協(xié)議名,根據(jù)需要填寫。例如http、https、ftp、datashare、dataability等。
  • scheme-specific-part: URI的特定解碼方案特定部分,由[//][authority][path][?query]組成,根據(jù)需要填寫。
    • authority: URI的解碼權(quán)限組件部分。由[userinfo@]host[:port]組成,根據(jù)需要填寫。
      • userinfo: 用戶信息,根據(jù)需要填寫。
      • host: 服務(wù)器的主機(jī)名部分,當(dāng)authority存在時(shí),此項(xiàng)必填。
      • port: 服務(wù)器端口,根據(jù)需要填寫。
    • path: 路徑信息,根據(jù)需要填寫。
    • query: 查詢部分,根據(jù)需要填寫。
  • fragment: 片段部分,根據(jù)需要填寫。

URI示例:

const result1 = new uri.URI("ftp://ftp.aaa.bbb.ccc/dddd/eee.txt");
console.log(result1.host) // ftp.aaa.bbb.ccc
console.log(result1.fragment) // null
console.log(result1.path) // /dddd/eee.txt
console.log(result1.scheme) // ftp
console.log(result1.userInfo) // null
console.log(result1.port) // -1
console.log(result1.query) // null

const result2 = new uri.URI("gopher://spinaltap.micro.umn.edu/00/Weather/California/Los%20Angeles#fragment");
console.log(result2.host) // spinaltap.micro.umn.edu
console.log(result2.fragment) // fragment
console.log(result2.path) // /00/Weather/California/Los Angeles
console.log(result2.scheme) // gopher
console.log(result2.userInfo) // null
console.log(result2.port) //-1
console.log(result2.query) // null

const result3 = new uri.URI("datashare:///com.samples.datasharetest.DataShare/DB00/TBL00");
console.log(result3.host) // null
console.log(result3.fragment) // null
console.log(result3.path) // /com.samples.datasharetest.DataShare/DB00/TBL00
console.log(result3.scheme) // datashare
console.log(result3.userInfo) // null
console.log(result3.port) // -1
console.log(result3.query) // null

const result4 = new uri.URI("https://username:password@host:8080/directory/file?foo=1&bar=2#fragment");
console.log(result4.host) // host
console.log(result4.fragment) // fragment
console.log(result4.path) // /directory/file
console.log(result4.scheme) // https
console.log(result4.userInfo) // username:password
console.log(result4.port) // 8080
console.log(result4.query) // foo=1&bar=2

const result5 = new uri.URI("dataability:///com.example.DataAbility");
console.log(result5.host) // null
console.log(result5.fragment) // null
console.log(result5.path) // /com.example.DataAbility:
console.log(result5.scheme) // dataability
console.log(result5.userInfo) // null
console.log(result5.port) // -1
console.log(result5.query) // null

constructor

constructor(uri: string)

constructor是URI的構(gòu)造函數(shù)。

系統(tǒng)能力: SystemCapability.Utils.Lang

參數(shù):

參數(shù)名類型必填說明
uristring入?yún)?duì)象。

錯(cuò)誤碼:

以下錯(cuò)誤碼的詳細(xì)介紹請(qǐng)參見[語言基礎(chǔ)類庫錯(cuò)誤碼]。

錯(cuò)誤碼ID錯(cuò)誤信息
10200002Invalid uri string.

示例:

let mm = 'https://username:password@host:8080/directory/file?foo=1&bar=2#fragment';
new uri.URI(mm); // Output 'https://username:password@host:8080/directory/file?foo=1&bar=2#fragment';
new uri.URI('https://username:password@host:8080'); // Output 'https://username:password@host:8080';

toString

toString(): string

系統(tǒng)能力: SystemCapability.Utils.Lang

返回適用于URI中的查詢字符串。

返回值:

類型說明
string返回網(wǎng)址的字符串序列化。

示例:

const result = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
let result1 = result.toString();

equals(deprecated)

equals(other: URI): boolean

判斷此URI是否與其他URI對(duì)象相等。

說明:

從API version 8開始支持,從API version 9開始廢棄,建議使用[equalsTo9+]替代。

系統(tǒng)能力: SystemCapability.Utils.Lang

參數(shù):

參數(shù)名類型必填說明
otherURI需要比較的URI對(duì)象。

返回值:

類型說明
boolean返回true表示相等,否則返回false。

示例:

const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
uriInstance.equals(uriInstance1);

equalsTo9+

equalsTo(other: URI): boolean

判斷此URI是否與其他URI對(duì)象相等。

系統(tǒng)能力: SystemCapability.Utils.Lang

參數(shù):

參數(shù)名類型必填說明
otherURI需要比較的URI對(duì)象。

返回值:

類型說明
boolean返回true表示相等,否則返回false。

示例:

const uriInstance = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('https://username:password@host:8080/directory/file?query=pppppp#qwer=da');
let result = uriInstance.equalsTo(uriInstance1);

checkIsAbsolute

checkIsAbsolute(): boolean

判斷此URI是否為絕對(duì)URI(是否定義了scheme組件)。

系統(tǒng)能力: SystemCapability.Utils.Lang

返回值:

類型說明
boolean如果是絕對(duì)URI返回true,否則返回false。

示例:

const uriInstance = new uri.URI('https://username:password@www.qwer.com:8080?query=pppppp');
console.log(`${uriInstance.checkIsAbsolute()}`); // true
const uriInstance1 = new uri.URI('xxx.com/suppliers.htm');
console.log(`${uriInstance1.checkIsAbsolute()}`); // false

normalize

HarmonyOSOpenHarmony鴻蒙文檔籽料:mau123789是v直接拿

normalize(): URI

規(guī)范化此URI的路徑。

系統(tǒng)能力: SystemCapability.Utils.Lang

返回值:

類型說明
URI返回一個(gè)path被規(guī)范化后的URI對(duì)象。

示例:

const uriInstance = new uri.URI('https://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp');
console.log(uriInstance.path); // /path/path1/../path2/./path3
let uriInstance1 = uriInstance.normalize();
console.log(uriInstance1.path); // /path/path2/path3

審核編輯 黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 字符串
    +關(guān)注

    關(guān)注

    1

    文章

    590

    瀏覽量

    22242
  • 鴻蒙
    +關(guān)注

    關(guān)注

    60

    文章

    2617

    瀏覽量

    44033
  • OpenHarmony
    +關(guān)注

    關(guān)注

    29

    文章

    3851

    瀏覽量

    18587
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    C++字符串string

    string是C++編程語言中的字符串。在C++中字符串處理可以使用c語言字符串形式char *,也可以使用string
    的頭像 發(fā)表于 07-10 00:26 ?2152次閱讀
    C++<b class='flag-5'>字符串</b>string

    ArkTS語言基礎(chǔ)-解析

    被設(shè)計(jì)用來傳輸和存儲(chǔ)數(shù)據(jù),是一種可擴(kuò)展標(biāo)記語言。語言基礎(chǔ)提供了[XML生成、解析與轉(zhuǎn)換]的能力。 URL、
    發(fā)表于 02-20 16:44

    鴻蒙原生應(yīng)用開發(fā)-ArkTS語言基礎(chǔ)概述

    擴(kuò)展標(biāo)記語言。語言基礎(chǔ)提供了XML生成、解析與轉(zhuǎn)換的能力。 URL、URI構(gòu)造和
    發(fā)表于 03-05 15:42

    實(shí)例解析Java字符串內(nèi)存管理方法

    Java[1]語言字符串操作提供了豐富的支持,它將字符串封裝在三個(gè)中并提供多種字符串操作接口。在Java應(yīng)用程序中,由于對(duì)
    發(fā)表于 10-27 10:20 ?1次下載
    實(shí)例<b class='flag-5'>解析</b>Java<b class='flag-5'>字符串</b>內(nèi)存管理方法

    C語言字符串轉(zhuǎn)數(shù)字實(shí)現(xiàn)方法

    在C/C++語言中沒有專門的字符串變量,通常用字符數(shù)組來存放字符串字符串是以“\0”作為結(jié)束符。C/C++提供了豐富的
    發(fā)表于 11-14 17:50 ?1.4w次閱讀

    strtok拆分字符串

    就是字符格式。有些場(chǎng)景需要使用多個(gè)處理器協(xié)同工作,比如單片機(jī)+openmv,它們之間需要通信,可以采用字符格式的編碼方式。操作字符串,無非是兩件事兒:生成字符串
    發(fā)表于 01-13 15:46 ?8次下載
    strtok拆分<b class='flag-5'>字符串</b>

    C語言總結(jié)_字符串全方位練習(xí)

    C語言字符串全方位練習(xí),涉及知識(shí)點(diǎn):字符串解析、大小寫判斷、字符串插入、字符串刪除、
    的頭像 發(fā)表于 08-14 09:41 ?1892次閱讀

    C語言-字符串處理

    字符串在C語言里使用非常多,因?yàn)楹芏鄶?shù)據(jù)處理都是文本,也就是字符串,特別是設(shè)備交互、web網(wǎng)頁交互返回的幾乎都是文本數(shù)據(jù)。 這篇文章就介紹字符串定義、和基本處理的方法。
    的頭像 發(fā)表于 08-14 10:05 ?2106次閱讀

    關(guān)于STEP7功能字符串轉(zhuǎn)換

    libraries---Standard Libray---TI-S7 Converting Blocks) FC編號(hào) 功能名稱 描述 FC5 DI_STRING 雙整數(shù)轉(zhuǎn)字符串 FC16
    的頭像 發(fā)表于 10-10 10:50 ?5039次閱讀

    C語言字符串的引用方式

    在C語言程序中,字符串是存放在字符數(shù)組中的。 2. 用字符數(shù)組存放一個(gè)字符串,可以通過數(shù)組名和下標(biāo)引用
    的頭像 發(fā)表于 03-10 14:57 ?2325次閱讀

    nuere-簡(jiǎn)單小巧快速的字符串解析

    neure是一個(gè)簡(jiǎn)單小巧的字符串解析, 我在開發(fā)aopt時(shí)為了優(yōu)化編譯時(shí)間而開發(fā)的替代regex的. 目前代碼架構(gòu)非常簡(jiǎn)單, 性能上比regex更快, 和nom的速度不相上下. 設(shè)
    的頭像 發(fā)表于 08-14 09:54 ?780次閱讀

    c語言字符串定義

    C語言是一種強(qiáng)大而廣泛使用的編程語言字符串是其中一個(gè)非常重要的概念。在C語言中,字符串是由一系列字符
    的頭像 發(fā)表于 11-24 10:02 ?2664次閱讀

    C語言字符串編譯函數(shù)介紹

    在C語言中,字符串實(shí)際上是使用null字符O'終止的一維字符數(shù)組。因此,一個(gè)以null結(jié)尾的字符串,包含了組成
    的頭像 發(fā)表于 03-07 16:18 ?735次閱讀
    C<b class='flag-5'>語言</b><b class='flag-5'>字符串</b>編譯函數(shù)介紹

    HarmonyOS開發(fā)案例:【購物APP】

    提供URI字符串解析的相關(guān)功能。
    的頭像 發(fā)表于 04-24 20:47 ?975次閱讀
    HarmonyOS開發(fā)案例:【購物APP】

    字符串字符數(shù)組的區(qū)別

    在編程語言中,字符串字符數(shù)組是兩種基本的數(shù)據(jù)結(jié)構(gòu),它們都用于存儲(chǔ)和處理文本數(shù)據(jù)。盡管它們?cè)诠δ苌嫌幸欢ǖ闹丿B,但在內(nèi)部表示、操作方式和使用場(chǎng)景上存在顯著差異。 1. 內(nèi)部表示 字符串
    的頭像 發(fā)表于 01-07 15:29 ?1137次閱讀