Skip to Content
Dismiss
創新
專為 AI 打造的平台

整合式、自動化、可將資料轉化為高效情報。

深入了解
Dismiss
拉斯維加斯,6 月 16-18 日
Pure//Accelerate® 2026

探索如何完整釋放資料價值。 

立即報名

什麼是 YAML?您可以編寫多行字串嗎?

YAML 對於“但又另一種加價語言”或“非加價語言的YAML”來說是很短的,後者用來強調YAML是用於資料而非文件。YAML 是一種資料序列化語言,用於寫入配置檔案,以部署基礎架構。舉例來說,如果您想將 Docker 應用程式部署到 Kubernetes您會使用 YAML 檔案來設定執行個體。YAML 是人類可讀的,因此在部署期間建立檔案並讀取說明非常簡單。

如果您是 YAML 新手,您很快就會意識到需要一種方法將串列分解為多行,這是網路上最常見的 YAML 問題之一。在本文章中,我們將探討 YAML 多行字串的兩種主要方法,以及其他一些常見問題。

YAML 與 Whitespace:須知事項

YAML 檔案使用空白字元和歸位字元,但內容會在擷取到特定資源時序列化。建立 YAML 檔案的開發人員可以使用縮排和間距來格式化文字,以便於閱讀。YAML 使用與其他語言相似的方式處理空白空間,因此您可以視需要擁有更多空間來格式化檔案。

如何打破 YAML 多線字串的界限

擷取 YAML 檔案時,有時可能想要將換行時間保留在多行字串中。以下列虛擬程式碼為例:

    金鑰:

            項目1

            項目2

            項目3

在每個明細項目 (例如項目 1、項目 2 和項目 3) 之後,您都會有歸位字元。如果您將 YAML 語法維持原樣,則字串會變成以下內容:

項目 1 項目 2 項目 3

此字串格式建立了一個長字串,而沒有任何換行格式,因此您可能要保留換行次數。文字操作者可以保留斷線。文學運算子是管道 (“|”) 字元。為維持換行,您的 YAML 語法應變更為以下項目:

    金鑰:|

            項目1

            項目2

            項目3

請注意“關鍵”指令之後的管道特性。當應用程式擷取 YAML 檔案時,會轉換成下列字串:

項目1\nitem2\nitem3

“\n” 字元代表一條新行。將這個字串列印到應用程式時,每個項目都會顯示附加的歸位符號,以保留 YAML 指令中的格式。

YAML 多線區塊 vs. 長線

對於長字串,您需要使用多行區塊來讀取 YAML 檔案。例如,如果您的 YAML 檔案中有 250 字的段落,您需要將句子分成多行區塊。除段落結尾外,您不想保留歸位字元。您可以格式化 YAML 檔案,以使用多行長字串,並將字串序列化,以附加空格到每個項目,而非新的行字元。 

若要使用空白字元而非附加新行,請使用折疊式(>)運算子:

    金鑰:>

            項目1

            項目2

            項目3

YAML 透過折疊的運算子,在建立字串時增加空間。字串如下:

項目1 項目2 項目3\n

YAML 多線常見問題

如何在 YAML 中插入換行次數?

使用常值運算子 (“|”),將保留 YAML 字串中的任何換行次數。使用歸位按鍵動作建立換行時,方式與在標準文件中建立換行時相同。以下範例保留 YAML 字串中的歸位符號:

    金鑰:|

            項目1

            項目2

            項目3

YAML 可以有空白行嗎?

可以,以文字區塊表示的字串也可以包含空白行。保留運算子(“|+”) 保留空白行,以及新的行字元。下列 YAML 是多行字串的範例,在區塊結尾處有兩個空行:

    金鑰: |+

            項目1

            項目2

            項目3

YAML 剖析器會顯示上述語法中的下列字串:

項目1\nitem2\nitem3\n\n

YAML 是否關心空白?

分頁空白是 YAML 中的非法字元,因此任何縮排都必須搭配標準單一空白字元使用。標籤可用於引用的字串中,但無法用於格式化 YAML 檔案。空白凹痕的一致性對於資料可讀性非常重要。

YAML 是否允許空間?

可以,您可以在 YAML 檔案中擁有標準空間。空格應用於縮排,而非標籤字元。標籤字元在剖析 YAML 檔案時可能導致錯誤。

04/2026
The CIO Playbook for Running VMs on Kubernetes
A strategic guide for CIOs redefining modern virtualization by running enterprise VMs on Kubernetes with Portworx®—securely, at scale, and across hybrid environments.
電子書
15 頁

查看重要資訊與活動

商展
Pure//Accelerate® 2026
June 16-18, 2026 | Resorts World Las Vegas

準備好參加今年度為您帶來最大價值的活動了嗎?

立即報名
PURE360 示範
探索、認識、體驗 Everpure。

存取隨取隨用影片與示範,了解 Everpure 的強大功效。

觀賞示範影片
影片
觀看影片:企業級資料雲端的價值。

Charlie Giancarlo 討論管理為何管理資料才是未來趨勢,而非儲存設備。發掘整合式做法如何革新企業級 IT 作業。

立即觀看
資源
傳統儲存裝置無法驅動未來。

現代化工作負載需求必須達到 AI 級速度、安全性與規模。您的技術棧準備好了嗎?

進行評估
您的瀏覽器已不受支援!

較舊版的瀏覽器通常存在安全風險。為讓您使用我們網站時得到最佳體驗,請更新為這些最新瀏覽器其中一個。

Personalize for Me
Steps Complete!
1
2
3
Continue where you left off
Personalize your Everpure experience
Select a challenge, or skip and build your own use case.
迎向未來的虛擬化策略

因應所有需求的儲存方案

任意規模皆可實行 AI 專案

資料管道、訓練、推論專用的高效能儲存裝置

防護資料遺失問題

保衛資料的網路彈性解決方案

降低雲端作業成本

Azure、AWS 與私有雲專用的高成本效益儲存裝置

加速應用程式與資料庫效能

低延遲儲存裝置,達成應用程式高效能

降低資料中心耗能與空間使用

高效資源運用的儲存裝置,改善資料中心運用率

Confirm your outcome priorities
Your scenario prioritizes the selected outcomes. You can modify or choose next to confirm.
Primary
Reduce My Storage Costs
Lower hardware and operational spend.
Primary
Strengthen Cyber Resilience
Detect, protect against, and recover from ransomware.
Primary
Simplify Governance and Compliance
Easy-to-use policy rules, settings, and templates.
Primary
Deliver Workflow Automation
Eliminate error-prone manual tasks.
Primary
Use Less Power and Space
Smaller footprint, lower power consumption.
Primary
Boost Performance and Scale
Predictability and low latency at any size.
What’s your role and industry?
We've inferred your role based on your scenario. Modify or confirm and select your industry.
Select your industry
Financial services
Government
Healthcare
Education
Telecommunications
Automotive
Hyperscaler
Electronic design automation
Retail
Service provider
Transportation
Which team are you on?
Technical leadership team
Defines the strategy and the decision making process
Infrastructure and Ops team
Manages IT infrastructure operations and the technical evaluations
Business leadership team
Responsible for achieving business outcomes
Security team
Owns the policies for security, incident management, and recovery
Application team
Owns the business applications and application SLAs
Describe your ideal environment
Tell us about your infrastructure and workload needs. We chose a few based on your scenario.
Select your preferred deployment
Hosted
Dedicated off-prem
On-prem
Your data center + edge
Public cloud
Public cloud only
Hybrid
Mix of on-prem and cloud
Select the workloads you need
Databases
Oracle, SQL Server, SAP HANA, open-source

Key benefits:

  • Instant, space-efficient snapshots

  • Near-zero-RPO protection and rapid restore

  • Consistent, low-latency performance

 

AI/ML and analytics
Training, inference, data lakes, HPC

Key benefits:

  • Predictable throughput for faster training and ingest

  • One data layer for pipelines from ingest to serve

  • Optimized GPU utilization and scale
Data protection and recovery
Backups, disaster recovery, and ransomware-safe restore

Key benefits:

  • Immutable snapshots and isolated recovery points

  • Clean, rapid restore with SafeMode™

  • Detection and policy-driven response

 

Containers and Kubernetes
Kubernetes, containers, microservices

Key benefits:

  • Reliable, persistent volumes for stateful apps

  • Fast, space-efficient clones for CI/CD

  • Multi-cloud portability and consistent ops
Cloud
AWS, Azure

Key benefits:

  • Consistent data services across clouds

  • Simple mobility for apps and datasets

  • Flexible, pay-as-you-use economics

 

Virtualization
VMs, vSphere, VCF, vSAN replacement

Key benefits:

  • Higher VM density with predictable latency

  • Non-disruptive, always-on upgrades

  • Fast ransomware recovery with SafeMode™

 

Data storage
Block, file, and object

Key benefits:

  • Consolidate workloads on one platform

  • Unified services, policy, and governance

  • Eliminate silos and redundant copies

 

What other vendors are you considering or using?
Thinking...
Your personalized, guided path
Get started with resources based on your selections.