.NET/スペースのみの文字列、空の文字列、サイズ0の文字列を判定する
の編集
Top
/
.NET
/
スペースのみの文字列、空の文字列、サイズ0の文字列を判定する
[
トップ
] [
編集
|
差分
|
バックアップ
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
.NET
.NET/.NETでpingを実現する・System.Net.NetworkInformation.Ping
.NET/ARPテーブルを取得し表示するサンプル・GetIpNetTable
.NET/CPUコア毎の使用率を取得する
.NET/CPU使用率を取得する
.NET/DateとDateTimeの違い
.NET/HttpClientを使って指定したURLのページを取得する
.NET/IPv4からMACアドレス取得する・SendARP
.NET/IPアドレスからホスト名を取得するサンプルコード
.NET/ListのStringをカンマ区切りにする方法
.NET/Listを配列に配列をListに変換する
.NET/NET6.0でSQLiteを使ってみた Microsoft.Data.Sqlite
.NET/ODBCを使用してデータベースに接続しSQLを実行するサンプル
.NET/String.Splitで空要素を残す、空要素を削除するオプションについて
.NET/StringBuilderをバイト配列に変換する
.NET/Stringの配列をCSVにする方法
.NET/UNIX時間への変換・DateTimeOffset
.NET/UNIX時間をDateTimeOffset, DateTimeにする
.NET/Web APIからJSONを取得し値を表示する・DataContractJsonSerializer
.NET/WMIを使って物理メモリ・仮想メモリの使用量等を取得する
.NET/アルファベットを大文字、小文字に変換する
.NET/インストールされているODBCドライバ一覧を取得するサンプル
.NET/コンソールプログラムからトースト通知をするサンプル
.NET/サスペンド前・復帰の時に処理を行いたい
.NET/スペースのみの文字列、空の文字列、サイズ0の文字列を判定する
.NET/スリープの抑止、モニター電源オフの抑止のサンプルコード
.NET/ターゲットにしている.NETを確認する操作手順
.NET/テキストファイルの読込・ReadAllText,ReadAllLines
.NET/テキストファイルの読込・StreamReader
.NET/テンポラリファイルの作成・ランダムな文字列の作成を作成する
.NET/テンポラリファイル名を取得する・GetRandomFileName
.NET/ディレクトリの有無を確認する
.NET/ネットワークカードの各種情報を取得するサンプルコード
.NET/バイト配列にファイルの内容をすべて読み込む
.NET/バイナリーファイルの作成・リード・ライト
.NET/ファイルなの?ディレクトリなの?の判別
.NET/ファイルの有無を確認する
.NET/ファイル一覧を取得する・GetFiles,EnumerateFiles
.NET/プログラムに渡された引数を取得する方法
.NET/ユーザーが無操作の状態を取得する・GetLastInputInfo
.NET/三項演算子のサンプルコード
.NET/四捨五入をするときはMidpointRounding.AwayFromZeroにすること
.NET/指定した時間間隔でイベントを発行する・Timer
.NET/数値を指定した桁数分ゼロで埋めたい・ToString
.NET/文字列(String)を左右逆転し文字列(String)で返却する方法
.NET/文字列をバイト配列に変換・バイト配列を文字列に変換
.NET/文字列を区切り文字で分割する方法・Split
.NET/文字列宣言の先頭の@について
.NET/文字列数値を指定した桁数分ゼロで埋めたい・PadLeft
.NET/文字列日付をDateTimeに変換する
.NET/文字列配列orList配列に指定した文字列が存在するかを確認する方法
.NET/時間(日数+時間)が格納できるTimeSpan
.NET/月末の日を取得する方法・DaysInMonth
.NET/現在の日時を取得する
.NET/符号付バイトsbyte,符号なしbyteをintegerに変換する
.NET/管理者として実行されているかどうか確認するサンプルコード
.NET/連想配列(ハッシュ)のキーと値を取得する
.NET/連想配列(ハッシュ)を使ってみる・Dictionary
.NET/閏年かを調べる方法
AutoTicketLinkName
FrontPage
MenuBar
OSS
OSS/XYM日本円価格(シンボル日本円価格 (XYMJPYPrice)
OSS/ビットコイン日本円価格(ビットコイン日本円価格 (BitcoinJPYPrice)
RecentDeleted
VS
VS/Debug.Writeをイミディエイトウィンドウに出力する方法
VS/Visual Studio 2022に Spy++をインストールする手順
VS/VS2022の配色テーマの変更操作
VS/XAML編集に使うツールボックスの再表示する操作手順
VS/インデントなどコードを整形するショートカットの紹介
VS/コメントにするショートカットキー
VS/ショートカットキーで大文字・小文字に変換する
VS/ビルド中に中断したい場合の操作手順
WPF
WPF/DataGridを使ってみる
WPF/起動してもMainWindowを表示したくない場合
お約束
プライバシーポリシー
最初にお読みください
#navi(../) * スペースのみの文字列、空の文字列、サイズ0の文字列を判定する [#dfe0a770] 半角スペースのみの文字列、null(Nothing)な文字列、サイズ0の文字列を判定する C#, Visual Basic のサンプルコードを紹介します。~ Stringクラスには半角スペースのみ、空の文字列、サイズ0の文字列を判定するのに、~ ''String.IsNullOrEmpty'', ''String.IsNullOrWhiteSpace'' という便利なメソッドがあります。~ #contents * 関連サイト [#q67072ae] -[[Microsoft .NET | String>https://docs.microsoft.com/ja-jp/dotnet/api/system.string]] * 動作確認環境 [#p0dcd7d0] - Windows 10 - Visual Studio 2019 - .NET Core 3.1 - コンソールアプリケーション #htmlinsert(windev-top.html) * C#, Visual Basic サンプルコードと実行結果 [#o97acfe9] 以下に''String.IsNullOrEmpty'', ''String.IsNullOrWhiteSpace''のサンプルコード紹介と実行結果を記します。~ 文字列が条件に成立すれば、true, 不成立であれば false が返却されます。~ 実際のプログラミングでは、ifにより判定することになりますね。 ** C# [#h5bf8e17] using System; class Program { static void Main(string[] args) { string empty = ""; string nothing = null; string white_space = @" "; Console.WriteLine("-- String.IsNullOrEmpty --"); Console.WriteLine("empty: " + String.IsNullOrEmpty(empty)); Console.WriteLine("nothing: " + String.IsNullOrEmpty(nothing)); Console.WriteLine("white_space: " + String.IsNullOrEmpty(white_space)); Console.WriteLine("-- String.IsNullOrWhiteSpace --"); Console.WriteLine("empty: " + String.IsNullOrWhiteSpace(empty)); Console.WriteLine("nothing: " + String.IsNullOrWhiteSpace(nothing)); Console.WriteLine("white_space: " + String.IsNullOrWhiteSpace(white_space)); } } ** Visual Basic [#y0f0085f] Imports System Module Program Sub Main(args As String()) Dim empty As String = "" Dim null As String = Nothing Dim white_space As String = " " Console.WriteLine("-- String.IsNullOrEmpty --") Console.WriteLine("empty: " & String.IsNullOrEmpty(empty)) Console.WriteLine("nothing: " & String.IsNullOrEmpty(Nothing)) Console.WriteLine("white_space: " & String.IsNullOrEmpty(white_space)) Console.WriteLine("-- String.IsNullOrWhiteSpace --") Console.WriteLine("empty: " & String.IsNullOrWhiteSpace(empty)) Console.WriteLine("nothing: " & String.IsNullOrWhiteSpace(Nothing)) Console.WriteLine("white_space: " & String.IsNullOrWhiteSpace(white_space)) End Sub End Module ** 実行結果 [#ab821c58] 上記のサンプルコードを実行したときのキャプチャになります。 #ref(01.png) 以上、''String.IsNullOrEmpty'', ''String.IsNullOrWhiteSpace''を使って、~ 空の文字列、サイズが0の文字列、半角スペースのみの文字列を判定するサンプルコードでした。
タイムスタンプを変更しない
#navi(../) * スペースのみの文字列、空の文字列、サイズ0の文字列を判定する [#dfe0a770] 半角スペースのみの文字列、null(Nothing)な文字列、サイズ0の文字列を判定する C#, Visual Basic のサンプルコードを紹介します。~ Stringクラスには半角スペースのみ、空の文字列、サイズ0の文字列を判定するのに、~ ''String.IsNullOrEmpty'', ''String.IsNullOrWhiteSpace'' という便利なメソッドがあります。~ #contents * 関連サイト [#q67072ae] -[[Microsoft .NET | String>https://docs.microsoft.com/ja-jp/dotnet/api/system.string]] * 動作確認環境 [#p0dcd7d0] - Windows 10 - Visual Studio 2019 - .NET Core 3.1 - コンソールアプリケーション #htmlinsert(windev-top.html) * C#, Visual Basic サンプルコードと実行結果 [#o97acfe9] 以下に''String.IsNullOrEmpty'', ''String.IsNullOrWhiteSpace''のサンプルコード紹介と実行結果を記します。~ 文字列が条件に成立すれば、true, 不成立であれば false が返却されます。~ 実際のプログラミングでは、ifにより判定することになりますね。 ** C# [#h5bf8e17] using System; class Program { static void Main(string[] args) { string empty = ""; string nothing = null; string white_space = @" "; Console.WriteLine("-- String.IsNullOrEmpty --"); Console.WriteLine("empty: " + String.IsNullOrEmpty(empty)); Console.WriteLine("nothing: " + String.IsNullOrEmpty(nothing)); Console.WriteLine("white_space: " + String.IsNullOrEmpty(white_space)); Console.WriteLine("-- String.IsNullOrWhiteSpace --"); Console.WriteLine("empty: " + String.IsNullOrWhiteSpace(empty)); Console.WriteLine("nothing: " + String.IsNullOrWhiteSpace(nothing)); Console.WriteLine("white_space: " + String.IsNullOrWhiteSpace(white_space)); } } ** Visual Basic [#y0f0085f] Imports System Module Program Sub Main(args As String()) Dim empty As String = "" Dim null As String = Nothing Dim white_space As String = " " Console.WriteLine("-- String.IsNullOrEmpty --") Console.WriteLine("empty: " & String.IsNullOrEmpty(empty)) Console.WriteLine("nothing: " & String.IsNullOrEmpty(Nothing)) Console.WriteLine("white_space: " & String.IsNullOrEmpty(white_space)) Console.WriteLine("-- String.IsNullOrWhiteSpace --") Console.WriteLine("empty: " & String.IsNullOrWhiteSpace(empty)) Console.WriteLine("nothing: " & String.IsNullOrWhiteSpace(Nothing)) Console.WriteLine("white_space: " & String.IsNullOrWhiteSpace(white_space)) End Sub End Module ** 実行結果 [#ab821c58] 上記のサンプルコードを実行したときのキャプチャになります。 #ref(01.png) 以上、''String.IsNullOrEmpty'', ''String.IsNullOrWhiteSpace''を使って、~ 空の文字列、サイズが0の文字列、半角スペースのみの文字列を判定するサンプルコードでした。
テキスト整形のルールを表示する
添付ファイル:
01.png
184件
[
詳細
]