URI字符串解析
說明: 本模塊首批接口從API version 8開始支持。后續版本的新增接口,采用上角標單獨標記接口的起始版本。 開發前請熟悉鴻蒙開發指導文檔 :[
gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
導入模塊
import uri from '@ohos.uri'
URI
屬性
系統能力: SystemCapability.Utils.Lang
名稱 | 參數類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
scheme | string | 是 | 否 | 獲取URI 的協議部分。 |
userInfo | string | 是 | 否 | 獲取 URI 的用戶信息部分。 |
host | string | 是 | 否 | 獲取 URI 的主機名部分(不帶端口)。 |
port | string | 是 | 否 | 獲取 URI 的端口部分。 |
path | string | 是 | 否 | 獲取 URI 的路徑部分。 |
query | string | 是 | 否 | 獲取 URI 的查詢部分。 |
fragment | string | 是 | 否 | 獲取 URI 的片段部分 |
authority | string | 是 | 否 | 獲取此URI的解碼權限組件部分。 |
ssp | string | 是 | 否 | 獲取URI的解碼方案特定部分。 |
constructor
constructor(uri: string)
constructor是URI的構造函數。
系統能力: SystemCapability.Utils.Lang
參數:
參數名 | 類型 | 可讀 | 可寫 | 說明 |
---|---|---|---|---|
uri | string | 是 | 是 | 入參對象。 |
示例:
var mm = 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment';
new uri.URI(mm); // Output 'http://username:password@host:8080/directory/file?foo=1&bar=2#fragment';
new uri.URI('http://username:password@host:8080'); // Output 'http://username:password@host:8080';
toString
toString(): string
系統能力: SystemCapability.Utils.Lang
返回適用于URL中的查詢字符串。
返回值:
類型 | 說明 |
---|---|
string | 返回網址的字符串序列化。 |
示例:
const url = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
url.toString()
equals
equals(other: URI): boolean
判斷此URI是否與其他URI對象相等。
系統能力: SystemCapability.Utils.Lang
參數:
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
other | [URI] | 是 | 需要比較的URI對象。 |
返回值:
類型 | 說明 |
---|---|
boolean | 返回true表示相等,否則返回false。 |
示例:
const uriInstance = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da');
const uriInstance1 = new uri.URI('http://username:password@host:8080/directory/file?query=pppppp#qwer=da#fragment');
uriInstance.equals(uriInstance1);
checkIsAbsolute
checkIsAbsolute(): boolean
判斷此URI是否為絕對URI(是否定義了scheme組件)。
系統能力: SystemCapability.Utils.Lang
返回值:
類型 | 說明 |
---|---|
boolean | 返回true表示該URI是否為絕對URI。 |
示例:
const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080?query=pppppp');
uriInstance.checkIsAbsolute();
normalize
normalize(): URI
規范化此URI的路徑。
系統能力: SystemCapability.Utils.Lang
返回值:
類型 | 說明HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿 |
---|---|
URI | 返回一個path被規范化后的URI對象。 |
示例:
const uriInstance = new uri.URI('http://username:password@www.qwer.com:8080/path/path1/../path2/./path3?query=pppppp');
let uriInstance1 = uriInstance.normalize();
uriInstance1.path;
審核編輯 黃宇
-
字符串
+關注
關注
1文章
589瀏覽量
21217 -
鴻蒙
+關注
關注
59文章
2570瀏覽量
43888
發布評論請先 登錄
sdk5鴻蒙利用文件管理器獲取文件Uri的過程
實例解析Java字符串內存管理方法

strtok拆分字符串

評論