.NETヘルプ Humanizerは、C#における入力文字列を文に変換するための多数のツールと拡張メソッドを提供します。 Jacob Mellor 更新日:2026年1月18日 IronPDF をダウンロード NuGet ダウンロード DLL ダウンロード Windows 版 無料トライアル LLM向けのコピー LLM向けのコピー LLM 用の Markdown としてページをコピーする ChatGPTで開く このページについてChatGPTに質問する ジェミニで開く このページについてGeminiに問い合わせる Grokで開く このページについてGrokに質問する 困惑の中で開く このページについてPerplexityに問い合わせる 共有する Facebook で共有 Xでシェア(Twitter) LinkedIn で共有 URLをコピー 記事をメールで送る Humanizerは、特にユーザーフレンドリーな形式で情報を表示する際に、データを扱うプロセスを簡素化し、人間らしくする強力で柔軟な.NETライブラリです。 日付を相対時間("3日前")に変換、複数形にし、数字を単語としてフォーマットするなど、C#.NETでタスクをエレガントに処理するためのツールと拡張メソッドを提供します。 この記事では、C#でのHumanizerの詳細なチュートリアルを説明します。 また、C# PDFライブラリのためにHumanizerとIronPDFを使用してPDFドキュメントを生成する方法についても説明します。 C#でのHumanizerのセットアップ Humanizerを始めるには、NuGet経由でライブラリをインストールする必要があります。 プロジェクトでは、パッケージマネージャコンソールを通じて次のコマンドでこれを行うことができます。 Install-Package Humanizer 代わりに、.NET Core CLIを使用している場合は、次のコマンドでHumanizerを追加できます。 dotnet add package Humanizer インストール後、適切な名前空間をC#ファイルに含めることでHumanizerを使用し始めることができます。 using Humanizer; using Humanizer; $vbLabelText $csharpLabel 日付と時間の人間化 Humanizer の最も一般的な用途の 1 つは、Humanize メソッドを使用して、日付と時刻を人間が読める形式、期間、数値、数量に変換することです。 これは、"2時間前"や"5日後"のような相対時間を表示する際に特に便利です。 例: 相対時間の人間化 using System; class HumanizerDemo { static void Main() { DateTime pastDate = DateTime.Now.AddDays(-3); // Humanize the past date, which converts it to a relative time format string humanizedTime = pastDate.Humanize(); // Output: "3 days ago" DateTime futureDate = DateTime.Now.AddHours(5); // Humanize the future date, presenting it in relative time string futureHumanizedTime = futureDate.Humanize(); // Output: "in 5 hours" Console.WriteLine("Humanized Past Date: " + humanizedTime); Console.WriteLine("Humanized Future Date: " + futureHumanizedTime); } } using System; class HumanizerDemo { static void Main() { DateTime pastDate = DateTime.Now.AddDays(-3); // Humanize the past date, which converts it to a relative time format string humanizedTime = pastDate.Humanize(); // Output: "3 days ago" DateTime futureDate = DateTime.Now.AddHours(5); // Humanize the future date, presenting it in relative time string futureHumanizedTime = futureDate.Humanize(); // Output: "in 5 hours" Console.WriteLine("Humanized Past Date: " + humanizedTime); Console.WriteLine("Humanized Future Date: " + futureHumanizedTime); } } $vbLabelText $csharpLabel Humanizerの拡張メソッドは、さまざまな時間単位を自動的に処理し、文法的な正確さも調整します。 TimeSpansの人間化 Humanizer は、オブジェクトを人間化することもできるため、読み取り可能な形式で期間を簡単に表示できます。 例: TimeSpanの人間化 using System; class TimeSpanHumanizerDemo { static void Main() { TimeSpan timeSpan = TimeSpan.FromMinutes(123); // Humanizing the TimeSpan into hours and minutes string humanizedTimeSpan = timeSpan.Humanize(2); // Output: "2 hours, 3 minutes" Console.WriteLine("Humanized TimeSpan: " + humanizedTimeSpan); } } using System; class TimeSpanHumanizerDemo { static void Main() { TimeSpan timeSpan = TimeSpan.FromMinutes(123); // Humanizing the TimeSpan into hours and minutes string humanizedTimeSpan = timeSpan.Humanize(2); // Output: "2 hours, 3 minutes" Console.WriteLine("Humanized TimeSpan: " + humanizedTimeSpan); } } $vbLabelText $csharpLabel 数値の処理 Humanizerは、数値を人間が読みやすい単語に変換し、序数を処理するためのいくつかのメソッドを提供します。 例: 数字を単語に変換する using System; class NumberHumanizerDemo { static void Main() { int number = 123; // Convert number to words string words = number.ToWords(); // Output: "one hundred and twenty-three" Console.WriteLine("Number in Words: " + words); } } using System; class NumberHumanizerDemo { static void Main() { int number = 123; // Convert number to words string words = number.ToWords(); // Output: "one hundred and twenty-three" Console.WriteLine("Number in Words: " + words); } } $vbLabelText $csharpLabel 例: 数字を序数に変換する using System; class OrdinalHumanizerDemo { static void Main() { int number = 21; // Convert number to ordinal words string ordinal = number.ToOrdinalWords(); // Output: "twenty-first" Console.WriteLine("Ordinal Number: " + ordinal); } } using System; class OrdinalHumanizerDemo { static void Main() { int number = 21; // Convert number to ordinal words string ordinal = number.ToOrdinalWords(); // Output: "twenty-first" Console.WriteLine("Ordinal Number: " + ordinal); } } $vbLabelText $csharpLabel 複数形と単数形の変換 Humanizerは、単語を単数形と複数形の間で簡単に変換することができ、量に基づいて動的に長文を生成するのに便利です。 例: 単語の複数化と単数化 using System; class PluralizationDemo { static void Main() { string singular = "car"; // Pluralize the word string plural = singular.Pluralize(); // Output: "cars" string word = "people"; // Singularize the word string singularForm = word.Singularize(); // Output: "person" Console.WriteLine("Plural of 'car': " + plural); Console.WriteLine("Singular of 'people': " + singularForm); } } using System; class PluralizationDemo { static void Main() { string singular = "car"; // Pluralize the word string plural = singular.Pluralize(); // Output: "cars" string word = "people"; // Singularize the word string singularForm = word.Singularize(); // Output: "person" Console.WriteLine("Plural of 'car': " + plural); Console.WriteLine("Singular of 'people': " + singularForm); } } $vbLabelText $csharpLabel Humanizerは、不規則な複数形と単数形も扱い、多様なユースケースに対して強力です。 Enumsのフォーマット EnumsはC#アプリケーションで名前付き定数のセットを表すために頻繁に使用されます。 Humanizerは、enum値を人間が読みやすい文字列に変換できます。 例: Enumsの人間化 using System; public enum MyEnum { FirstValue, SecondValue } class EnumHumanizerDemo { static void Main() { MyEnum enumValue = MyEnum.FirstValue; // Humanizing enum to a readable format string humanizedEnum = enumValue.Humanize(); // Output: "First value" Console.WriteLine("Humanized Enum: " + humanizedEnum); } } using System; public enum MyEnum { FirstValue, SecondValue } class EnumHumanizerDemo { static void Main() { MyEnum enumValue = MyEnum.FirstValue; // Humanizing enum to a readable format string humanizedEnum = enumValue.Humanize(); // Output: "First value" Console.WriteLine("Humanized Enum: " + humanizedEnum); } } $vbLabelText $csharpLabel このメソッドは、UIでユーザーフレンドリーなラベルを表示する際に特に便利です。 バイトサイズの人間化 Humanizerのもう一つの便利な機能はバイトサイズを人間化し、大きなバイト値をKB、MB、GBなどの読みやすい形式に変換することです。 例: バイトサイズの人間化 using System; class ByteSizeHumanizerDemo { static void Main() { long bytes = 1048576; // Humanize bytes to a readable size format string humanizedBytes = bytes.Bytes().Humanize(); // Output: "1 MB" Console.WriteLine("Humanized Byte Size: " + humanizedBytes); } } using System; class ByteSizeHumanizerDemo { static void Main() { long bytes = 1048576; // Humanize bytes to a readable size format string humanizedBytes = bytes.Bytes().Humanize(); // Output: "1 MB" Console.WriteLine("Humanized Byte Size: " + humanizedBytes); } } $vbLabelText $csharpLabel 高度なシナリオ Humanizerは、上記の基本的なシナリオに限られません。 Truncate メソッドや複数の言語および拡張機能などの幅広い高度な機能をサポートしています。 例: DateTimeオフセットの人間化 Humanizer は DateTimeOffset も処理できるため、タイムゾーンを扱うアプリケーションに役立ちます。 using System; class DateTimeOffsetHumanizerDemo { static void Main() { DateTimeOffset dateTimeOffset = DateTimeOffset.Now.AddDays(-2); // Humanize DateTimeOffset string humanizedDateTimeOffset = dateTimeOffset.Humanize(); // Output: "2 days ago" Console.WriteLine("Humanized DateTimeOffset: " + humanizedDateTimeOffset); } } using System; class DateTimeOffsetHumanizerDemo { static void Main() { DateTimeOffset dateTimeOffset = DateTimeOffset.Now.AddDays(-2); // Humanize DateTimeOffset string humanizedDateTimeOffset = dateTimeOffset.Humanize(); // Output: "2 days ago" Console.WriteLine("Humanized DateTimeOffset: " + humanizedDateTimeOffset); } } $vbLabelText $csharpLabel パフォーマンスの考慮事項 Humanizerは効率的に設計されていますが、他のライブラリと同様に、そのパフォーマンスは使用方法に依存します。 特に大規模なデータセットやリアルタイム処理を扱う高性能を必要とするアプリケーションの場合、頻繁な人間化操作の影響を考慮することが重要です。 IronPDF for C IronPDFは、.NETアプリケーション向けの包括的なPDF生成および操作ライブラリです。 開発者がPDFファイルを簡単に作成、読み取り、編集、およびコンテンツを抽出することを可能にします。 IronPDFは、ユーザーフレンドリーな設計で、HTMLからPDFへの変換、ドキュメントのマージ、透かしの追加など、多くの機能を提供します。 その多機能性と強力な機能は、C#プロジェクトでのPDFドキュメントの処理に最適です。 NuGetパッケージマネージャを使用したIronPDFのインストール NuGetパッケージマネージャを使用してIronPDFをインストールする手順は次の通りです。 Visual Studio でプロジェクトを開きます。 Visual Studioを起動し、既存のC#プロジェクトを開くか、新しいプロジェクトを作成します。 NuGetパッケージ マネージャーを開きます。 ソリューションエクスプローラでプロジェクトを右クリックします。 コンテキストメニューから"Manage NuGet Packages…"を選択します。 IronPDFをインストールします。 NuGetパッケージマネージャで"参照"タブに移動します。 IronPDFを検索します。 検索結果からIronPDFパッケージを選択します。 "インストール"ボタンをクリックして、プロジェクトにIronPDFを追加します。 これらの手順に従うことで、IronPDFがインストールされ、プロジェクトでのPDF操作の強力な機能を活用できるようになります。 C# HumanizerおよびIronPDFコード例 using Humanizer; using IronPdf; using System; using System.Collections.Generic; class PDFGenerationDemo { static void Main() { // Instantiate the PDF renderer var renderer = new ChromePdfRenderer(); // Generate humanized content List<string> content = GenerateHumanizedContent(); // HTML content template for the PDF string htmlContent = "<h1>Humanizer Examples</h1><ul>"; // Build the list items to add to the HTML content foreach (var item in content) { htmlContent += $"<li>{item}</li>"; } htmlContent += "</ul>"; // Render the HTML into a PDF document var pdf = renderer.RenderHtmlAsPdf(htmlContent); // Save the PDF to a file pdf.SaveAs("output.pdf"); Console.WriteLine("PDF document generated successfully: output.pdf"); } /// <summary> /// Generates a list of humanized content examples /// </summary> /// <returns>List of humanized content as strings</returns> static List<string> GenerateHumanizedContent() { List<string> content = new List<string>(); // DateTime examples DateTime pastDate = DateTime.Now.AddDays(-3); DateTime futureDate = DateTime.Now.AddHours(5); content.Add($"DateTime.Now: {DateTime.Now}"); content.Add($"3 days ago: {pastDate.Humanize()}"); content.Add($"In 5 hours: {futureDate.Humanize()}"); // TimeSpan examples TimeSpan timeSpan = TimeSpan.FromMinutes(123); content.Add($"TimeSpan of 123 minutes: {timeSpan.Humanize()}"); // Number examples int number = 12345; content.Add($"Number 12345 in words: {number.ToWords()}"); content.Add($"Ordinal of 21: {21.ToOrdinalWords()}"); // Pluralization examples string singular = "car"; content.Add($"Plural of 'car': {singular.Pluralize()}"); string plural = "children"; content.Add($"Singular of 'children': {plural.Singularize()}"); // Byte size examples long bytes = 1048576; content.Add($"1,048,576 bytes: {bytes.Bytes().Humanize()}"); return content; } } using Humanizer; using IronPdf; using System; using System.Collections.Generic; class PDFGenerationDemo { static void Main() { // Instantiate the PDF renderer var renderer = new ChromePdfRenderer(); // Generate humanized content List<string> content = GenerateHumanizedContent(); // HTML content template for the PDF string htmlContent = "<h1>Humanizer Examples</h1><ul>"; // Build the list items to add to the HTML content foreach (var item in content) { htmlContent += $"<li>{item}</li>"; } htmlContent += "</ul>"; // Render the HTML into a PDF document var pdf = renderer.RenderHtmlAsPdf(htmlContent); // Save the PDF to a file pdf.SaveAs("output.pdf"); Console.WriteLine("PDF document generated successfully: output.pdf"); } /// <summary> /// Generates a list of humanized content examples /// </summary> /// <returns>List of humanized content as strings</returns> static List<string> GenerateHumanizedContent() { List<string> content = new List<string>(); // DateTime examples DateTime pastDate = DateTime.Now.AddDays(-3); DateTime futureDate = DateTime.Now.AddHours(5); content.Add($"DateTime.Now: {DateTime.Now}"); content.Add($"3 days ago: {pastDate.Humanize()}"); content.Add($"In 5 hours: {futureDate.Humanize()}"); // TimeSpan examples TimeSpan timeSpan = TimeSpan.FromMinutes(123); content.Add($"TimeSpan of 123 minutes: {timeSpan.Humanize()}"); // Number examples int number = 12345; content.Add($"Number 12345 in words: {number.ToWords()}"); content.Add($"Ordinal of 21: {21.ToOrdinalWords()}"); // Pluralization examples string singular = "car"; content.Add($"Plural of 'car': {singular.Pluralize()}"); string plural = "children"; content.Add($"Singular of 'children': {plural.Singularize()}"); // Byte size examples long bytes = 1048576; content.Add($"1,048,576 bytes: {bytes.Bytes().Humanize()}"); return content; } } $vbLabelText $csharpLabel 結論 Humanizerは、.NET開発者が人間に優しく、読みやすい形式で情報を提供するアプリケーションを作成するためには欠かせないライブラリです。 日時の人間化から数値や列挙型のフォーマットまでの幅広い機能が、アプリケーションの使いやすさを向上させるための多用途のツールとなっています。 Humanizerを利用することで、開発者はカスタムフォーマットロジックの実装にかかる時間と労力を節約し、アプリケーションがエンドユーザーにデータをより効果的に伝えることを保証します。 同様に、IronPDFは包括的なPDF生成と操作の機能を提供し、C#プロジェクトでのPDFドキュメントの作成と処理に最適です。 HumanizerとIronPDFを組み合わせることで、.NETアプリケーションの機能とプレゼンテーションが大幅に向上します。 IronPDFのライセンスについての詳細は、IronPDFライセンス情報を参照してください。 詳しくは、HTMLからPDFへの変換に関する詳細チュートリアルをチェックしてください。 よくある質問 C# における Humanizer ライブラリの目的は何ですか? C# の Humanizer ライブラリは、データを人間が理解しやすい形式に変換することを目的としています。たとえば、日付を相対時間文字列に変換することや、単語の複数形化、数字を単語としてフォーマットすること、列挙型を扱うことなどがあります。これにより、開発者はデータをより読みやすくアクセスしやすい形で提示することができます。 C# で DateTime を相対時間文字列に変換するにはどうすればよいですか? DateTime オブジェクトを相対時間の文字列に変換するには、Humanizer の Humanize メソッドを使用します。例えば「3 日前」や「5 時間後」のように表示されます。 C# プロジェクトに Humanizer ライブラリをインストールする方法は? C# プロジェクトに Humanizer ライブラリをインストールするには、NuGet パッケージ マネージャー コンソールで Install-Package Humanizer のコマンドを使用するか、.NET Core CLI で dotnet add package Humanizer を使用します。 Humanizer で可能なデータ変換の例をいくつか教えてください。 Humanizer はいくつかのデータ変換を実行できます。たとえば、Pascal ケースの文字列を文章に変換したり、アンダースコア付き文字列をタイトル ケースに変換したり、長いテキストを指定の長さに切り詰めたりします。 C# の単語の複数形化を Humanizer で支援できますか? はい、Humanizer には単語を複数形化および単数形化するためのメソッドがあり、通常形や不規則形の変換に対応しています。例えば「car」を「cars」に、「people」を「person」に変換します。 Humanizer は C# で列挙型をどのように処理しますか? Humanizerはenum値を人間に読みやすい文字列に変換でき、インターフェースでユーザー向けのラベルを表示しやすくします。 C# PDF ライブラリにはどのような機能がありますか? IronPDF のような C# PDF ライブラリは、PDF ファイルの作成、読み取り、編集、およびコンテンツ抽出などの機能を提供します。また、HTML を PDF に変換したり、ドキュメントをマージしたり、ウォーターマークを追加することもできます。 プロジェクトに C# PDF ライブラリをインストールするにはどうすれば良いですか? C# PDF ライブラリをインストールするには、「ブラウズ」タブでライブラリ名(例:IronPDF)を検索し、「インストール」をクリックします。 C# で Humanizer と PDF ライブラリを組み合わせることの利点は何ですか? Humanizer と IronPDF のような PDF ライブラリを組み合わせることで、Humanizer によって人間が読みやすいコンテンツを生成し、それを PDF ドキュメントに変換できるため、ユーザーフレンドリーな PDF レポートやドキュメントを作成するのが容易になります。 Humanizer 使用時のパフォーマンスについて考慮すべきことは何ですか? Humanizer は効率的に設計されていますが、大規模なデータセットやリアルタイム処理が必要なアプリケーションでは、頻繁なヒューマニゼーション操作の影響を考慮する必要があります。 Jacob Mellor 今すぐエンジニアリングチームとチャット 最高技術責任者(CTO) ジェイコブ・メラーはIron Softwareの最高技術責任者(CTO)であり、C# PDFテクノロジーを開拓する先見的なエンジニアです。Iron Softwareのコアコードベースを支えるオリジナル開発者として、彼は創業以来、会社の製品アーキテクチャを形成し、CEOのCameron Rimingtonとともに、会社をNASA、Tesla、および世界的な政府機関にサービスを提供する50人以上の会社に変えました。1999年にロンドンで最初のソフトウェアビジネスを開業し、2005年に最初 for .NETコンポーネントを作成した後、Microsoftのエコシステム全体で複雑な問題を解決することを専門としました。彼の主要なIronPDFとIron Suite .NETライブラリは、世界中で3000万以上のNuGetインストールを達成し、彼の基礎となるコードは世界中で使用されている開発者ツールに力を与え続けています。25年の商業経験と41年のコーディングの専門知識を持つJacobは、次世代の技術リーダーを指導しながら、エンタープライズグレードのC#、Java、Python PDFテクノロジーにおけるイノベーションの推進に注力しています。 関連する記事 更新日 2026年2月20日 CLIの簡素化と.NETの橋渡し:Curl DotNetとIronPDFを使う Jacob Mellorは、.NETエコシステムにcURLの親しみやすさをもたらすために作成されたライブラリ、CurlDotNetでこのギャップを埋めました。 詳しく読む 更新日 2025年12月20日 RandomNumberGenerator C# RandomNumberGenerator C#クラスを使用すると、PDF生成および編集プロジェクトを次のレベルに引き上げることができます 詳しく読む 更新日 2025年12月20日 C# String Equals(開発者向けの仕組み) 強力なPDFライブラリであるIronPDFと組み合わせることで、switchパターンマッチングは、ドキュメント処理のためのよりスマートでクリーンなロジックを構築できます 詳しく読む TensorFlow .NET(開発者向けの動作方法)OpenAPI .NET(開発者向けの...
更新日 2026年2月20日 CLIの簡素化と.NETの橋渡し:Curl DotNetとIronPDFを使う Jacob Mellorは、.NETエコシステムにcURLの親しみやすさをもたらすために作成されたライブラリ、CurlDotNetでこのギャップを埋めました。 詳しく読む
更新日 2025年12月20日 RandomNumberGenerator C# RandomNumberGenerator C#クラスを使用すると、PDF生成および編集プロジェクトを次のレベルに引き上げることができます 詳しく読む
更新日 2025年12月20日 C# String Equals(開発者向けの仕組み) 強力なPDFライブラリであるIronPDFと組み合わせることで、switchパターンマッチングは、ドキュメント処理のためのよりスマートでクリーンなロジックを構築できます 詳しく読む