-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
content/uiux/concepts/design-software/design-software.md | ||
content/ruby/concepts/gems/gems.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
content/c-sharp/concepts/strings/terms/tochararray/tochararray.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
--- | ||
Title: '.ToCharArray()' | ||
Description: 'Converts a string into an array of characters.' | ||
Subjects: | ||
- 'Computer Science' | ||
- 'Code Foundations' | ||
Tags: | ||
- 'Strings' | ||
- 'Methods' | ||
CatalogContent: | ||
- 'learn-c-sharp' | ||
- 'paths/computer-science' | ||
--- | ||
|
||
The **`.ToCharArray()`** method in C# converts a string into an array of characters, where each character in the string becomes an element in the resulting array. This allows for the manipulation or iteration of individual characters. | ||
|
||
## Syntax | ||
|
||
```pseudo | ||
char[] arrayName = stringName.ToCharArray(); | ||
``` | ||
|
||
- `stringName`: The string to be converted into a character array. | ||
- `arrayName`: The resulting array containing individual characters from the string. | ||
|
||
### Optional Parameters | ||
|
||
The `.ToCharArray()` method can also take optional parameters to convert a specific substring into a character array: | ||
|
||
```pseudo | ||
char[] substringArray = stringName.ToCharArray(startIndex, length); | ||
``` | ||
|
||
- `startIndex`: The zero-based index where the substring starts. | ||
- `length`: The number of characters to include in the resulting array, starting from `startIndex`. | ||
|
||
## Examples | ||
|
||
### Split into Individual Characters | ||
|
||
Here's an example of using `.ToCharArray()` to split a string into individual characters: | ||
|
||
```cs | ||
using System; | ||
|
||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
string greeting = "Hello, World!"; | ||
char[] charArray = greeting.ToCharArray(); | ||
|
||
foreach (char c in charArray) | ||
{ | ||
Console.WriteLine(c); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
The output of the above code will be as follows: | ||
|
||
```shell | ||
H | ||
e | ||
l | ||
l | ||
o | ||
, | ||
|
||
W | ||
o | ||
r | ||
l | ||
d | ||
! | ||
``` | ||
|
||
### Converting a Substring to a Character Array | ||
|
||
```cs | ||
using System; | ||
|
||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
string phrase = "Convert this string!"; | ||
char[] partialArray = phrase.ToCharArray(8, 4); | ||
|
||
foreach (char c in partialArray) | ||
{ | ||
Console.WriteLine(c); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
The output of the above code will be as follows: | ||
|
||
```shell | ||
t | ||
h | ||
i | ||
s | ||
``` | ||
|
||
## Codebyte Example | ||
|
||
Run the following codebyte example to see how `.ToCharArray()` works in C#: | ||
|
||
```codebyte/csharp | ||
using System; | ||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
string example = "Learn C#"; | ||
char[] charArray = example.ToCharArray(); | ||
Console.WriteLine("Character Array:"); | ||
foreach (char c in charArray) | ||
{ | ||
Console.Write(c + " "); | ||
} | ||
} | ||
} | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
Title: 'String Functions' | ||
Description: 'String functions in SQL allow for operations such as modifying, formatting, and extracting information from strings.' | ||
Subjects: | ||
- 'Data Science' | ||
- 'Data Visualization' | ||
Tags: | ||
- 'Database' | ||
- 'Functions' | ||
- 'SQL' | ||
- 'Strings' | ||
CatalogContent: | ||
- 'learn-sql' | ||
- 'paths/analyze-data-with-sql' | ||
--- | ||
|
||
**String functions** in SQL allow for various operations such as modifying, formatting, and extracting information from strings. | ||
|
||
These functions are commonly used in data analysis, database management, and report generation to clean and process text-based data efficiently. | ||
|
||
## Common String Functions | ||
|
||
Here are some widely used SQL string functions: | ||
|
||
| **Function** | **Syntax** | **Description** | | ||
| ------------ | ------------------------------------------------ | ---------------------------------------------------------------------------- | | ||
| `CONCAT` | `CONCAT(string1, string2, ...)` | Combines two or more strings into one. | | ||
| `SUBSTRING` | `SUBSTRING(string, start_position, length)` | Extracts a portion of a string based on starting position and length. | | ||
| `LENGTH` | `LENGTH(string)` | Returns the number of characters in a string. | | ||
| `TRIM` | `TRIM([characters] FROM string)` | Removes leading and trailing spaces (or specified characters) from a string. | | ||
| `UPPER` | `UPPER(string)` | Converts a string to uppercase. | | ||
| `LOWER` | `LOWER(string)` | Converts a string to lowercase. | | ||
| `REPLACE` | `REPLACE(string, search_string, replace_string)` | Replaces occurrences of a substring within a string with another substring. | | ||
| `LEFT` | `LEFT(string, number_of_characters)` | Extracts a specified number of characters from the start of a string. | | ||
| `RIGHT` | `RIGHT(string, number_of_characters)` | Extracts a specified number of characters from the end of a string. | | ||
| `INSTR` | `INSTR(string, substring)` | Returns the position of the first occurrence of a substring within a string. | | ||
|
||
## Example | ||
|
||
Assume there is a `users` table with the following data: | ||
|
||
| first_name | last_name | email | | ||
| ---------- | --------- | ------------------------ | | ||
| John | Doe | [email protected] | | ||
| Alice | Johnson | [email protected] | | ||
| Robert | Smith | [email protected] | | ||
|
||
Here's an example that uses string functions: | ||
|
||
```sql | ||
SELECT | ||
CONCAT(UPPER(SUBSTRING(first_name, 1, 1)), '.', UPPER(last_name)) AS formatted_name, | ||
LENGTH(email) AS email_length, | ||
REPLACE(email, '@', '[at]') AS obfuscated_email | ||
FROM users; | ||
``` | ||
|
||
This example will generate the following output: | ||
|
||
```shell | ||
| formatted_name | email_length | obfuscated_email | | ||
|----------------|--------------|----------------------------| | ||
| J.DOE | 21 | john.doe[at]example.com | | ||
| A.JOHNSON | 25 | alice.johnson[at]work.org | | ||
| R.SMITH | 26 | robert.smith[at]company.net| | ||
``` |