Skip to content

Commit f7567d5

Browse files
committed
Add project+modules for F# String.IsNullOrEmpty snippets
1 parent 7e63510 commit f7567d5

File tree

6 files changed

+74
-47
lines changed

6 files changed

+74
-47
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="inoe.fs" />
10+
<Compile Include="NullString1.fs" />
11+
<Compile Include="NullString2.fs" />
12+
<Compile Include="isnullorempty1.fs" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1+
namespace IsNullOrEmpty
12
open System
23

3-
// <Snippet2>
4-
let (s: string) = null
4+
module NullString1 =
55

6-
printfn "The value of the string is '%s'" s
6+
// <Snippet2>
7+
let (s: string) = null
78

8-
try
9-
printfn "String length is %d" s.Length
10-
with
11-
| :? NullReferenceException as ex -> printfn "%s" ex.Message
9+
printfn "The value of the string is '%s'" s
1210

13-
// The example displays the following output:
14-
// The value of the string is ''
15-
// Object reference not set to an instance of an object.
16-
// </Snippet2>
11+
try
12+
printfn "String length is %d" s.Length
13+
with
14+
| :? NullReferenceException as ex -> printfn "%s" ex.Message
1715

18-
19-
// <Snippet3>
20-
let s = ""
21-
printfn "The length of '%s' is %d." s s.Length
22-
23-
// The example displays the following output:
24-
// The length of '' is 0.
25-
// </Snippet3>
16+
// The example displays the following output:
17+
// The value of the string is ''
18+
// Object reference not set to an instance of an object.
19+
// </Snippet2>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace IsNullOrEmpty
2+
open System
3+
4+
module NullString2 =
5+
6+
// <Snippet3>
7+
let s = ""
8+
printfn "The length of '%s' is %d." s s.Length
9+
10+
// The example displays the following output:
11+
// The length of '' is 0.
12+
// </Snippet3>
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
namespace IsNullOrEmpty
12
open System
23

3-
//<Snippet1>
4-
let test (s: string): string =
5-
if String.IsNullOrEmpty(s)
6-
then "is null or empty"
7-
else $"(\"{s}\") is neither null nor empty"
4+
module Inoe =
85

9-
let s1 = "abcd"
10-
let s2 = ""
11-
let s3 = null
6+
//<Snippet1>
7+
let test (s: string): string =
8+
if String.IsNullOrEmpty(s)
9+
then "is null or empty"
10+
else $"(\"{s}\") is neither null nor empty"
1211

13-
printfn "String s1 %s" (test s1)
14-
printfn "String s2 %s" (test s2)
15-
printfn "String s2 %s" (test s3)
12+
let s1 = "abcd"
13+
let s2 = ""
14+
let s3 = null
1615

17-
// The example displays the following output:
18-
// String s1 ("abcd") is neither null nor empty.
19-
// String s2 is null or empty.
20-
// String s3 is null or empty.
21-
//</Snippet1>
16+
printfn "String s1 %s" (test s1)
17+
printfn "String s2 %s" (test s2)
18+
printfn "String s2 %s" (test s3)
19+
20+
// The example displays the following output:
21+
// String s1 ("abcd") is neither null nor empty.
22+
// String s2 is null or empty.
23+
// String s3 is null or empty.
24+
//</Snippet1>
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
namespace IsNullOrEmpty
12
open System
23

3-
// <Snippet1>
4-
let testForNullOrEmpty (s: string): bool =
5-
s = null || s = String.Empty
4+
module IsNullOrEmpty1 =
65

7-
let s1 = null
8-
let s2 = ""
6+
// <Snippet1>
7+
let testForNullOrEmpty (s: string): bool =
8+
s = null || s = String.Empty
99

10-
printfn "%b" (testForNullOrEmpty s1)
11-
printfn "%b" (testForNullOrEmpty s2)
10+
let s1 = null
11+
let s2 = ""
1212

13-
// The example displays the following output:
14-
// true
15-
// true
16-
// </Snippet1>
13+
printfn "%b" (testForNullOrEmpty s1)
14+
printfn "%b" (testForNullOrEmpty s2)
15+
16+
// The example displays the following output:
17+
// true
18+
// true
19+
// </Snippet1>

xml/System/String.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8388,7 +8388,7 @@ A string is empty if it is explicitly assigned an empty string ("") or <xref:Sy
83888388
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.isnullorempty/cpp/NullString1.cpp" id="Snippet3":::
83898389
:::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrEmpty/NullString1.cs" interactive="try-dotnet-method" id="Snippet3":::
83908390
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorempty/vb/NullString1.vb" id="Snippet3":::
8391-
:::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrEmpty/NullString1.fs" interactive="try-dotnet-method" id="Snippet3":::
8391+
:::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrEmpty/NullString2.fs" interactive="try-dotnet-method" id="Snippet3":::
83928392

83938393
## Examples
83948394
The following example examines three strings and determines whether each string has a value, is an empty string, or is `null`.

0 commit comments

Comments
 (0)