@@ -115,9 +115,6 @@ public static bool IsNullOrWhiteSpace(this string str)
115
115
/// <summary>
116
116
/// Gets a substring of a string from beginning of the string.
117
117
/// </summary>
118
- /// <param name="str"></param>
119
- /// <param name="len"></param>
120
- /// <returns></returns>
121
118
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
122
119
/// <exception cref="ArgumentException">Thrown if <paramref name="len"/> is bigger that string's length</exception>
123
120
public static string Left ( this string str , int len )
@@ -135,6 +132,14 @@ public static string Left(this string str, int len)
135
132
return str . Substring ( 0 , len ) ;
136
133
}
137
134
135
+ /// <summary>
136
+ /// Converts line endings in the string to <see cref="Environment.NewLine"/>.
137
+ /// </summary>
138
+ public static string NormalizeLineEndings ( this string str )
139
+ {
140
+ return str . Replace ( "\r \n " , "\n " ) . Replace ( "\r " , "\n " ) . Replace ( "\n " , Environment . NewLine ) ;
141
+ }
142
+
138
143
/// <summary>
139
144
/// Gets index of nth occurence of a char in a string.
140
145
/// </summary>
@@ -168,9 +173,6 @@ public static int NthIndexOf(this string str, char c, int n)
168
173
/// <summary>
169
174
/// Gets a substring of a string from end of the string.
170
175
/// </summary>
171
- /// <param name="str"></param>
172
- /// <param name="len"></param>
173
- /// <returns></returns>
174
176
/// <exception cref="ArgumentNullException">Thrown if <paramref name="str"/> is null</exception>
175
177
/// <exception cref="ArgumentException">Thrown if <paramref name="len"/> is bigger that string's length</exception>
176
178
public static string Right ( this string str , int len )
@@ -188,6 +190,37 @@ public static string Right(this string str, int len)
188
190
return str . Substring ( str . Length - len , len ) ;
189
191
}
190
192
193
+ /// <summary>
194
+ /// Uses string.Split method to split given string by given separator.
195
+ /// </summary>
196
+ public static string [ ] Split ( this string str , string separator )
197
+ {
198
+ return str . Split ( new [ ] { separator } , StringSplitOptions . None ) ;
199
+ }
200
+
201
+ /// <summary>
202
+ /// Uses string.Split method to split given string by given separator.
203
+ /// </summary>
204
+ public static string [ ] Split ( this string str , string separator , StringSplitOptions options )
205
+ {
206
+ return str . Split ( new [ ] { separator } , options ) ;
207
+ }
208
+
209
+ /// <summary>
210
+ /// Uses string.Split method to split given string by <see cref="Environment.NewLine"/>.
211
+ /// </summary>
212
+ public static string [ ] SplitToLines ( this string str )
213
+ {
214
+ return str . Split ( Environment . NewLine ) ;
215
+ }
216
+
217
+ /// <summary>
218
+ /// Uses string.Split method to split given string by <see cref="Environment.NewLine"/>.
219
+ /// </summary>
220
+ public static string [ ] SplitToLines ( this string str , StringSplitOptions options )
221
+ {
222
+ return str . Split ( Environment . NewLine , options ) ;
223
+ }
191
224
192
225
/// <summary>
193
226
/// Converts PascalCase string to camelCase string.
@@ -333,7 +366,7 @@ public static string TruncateWithPostfix(this string str, int maxLength, string
333
366
{
334
367
return string . Empty ;
335
368
}
336
-
369
+
337
370
if ( str . Length <= maxLength )
338
371
{
339
372
return str ;
0 commit comments