Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
PragatiVerma18 authored Dec 16, 2024
2 parents ef3f2fe + 4bdf533 commit 6c1d3f0
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/concept-of-the-week.txt
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
2 changes: 1 addition & 1 deletion content/ai/concepts/generative-ai/generative-ai.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
Title: 'Generative AI'
Description: 'Generative AI (GenAI) involves the creation of new and unique digital content. Before GenAI digital content of this level could only be created by human beings. These unique creations are driven by natural language prompts.'
Description: 'Generative AI (GenAI) uses AI to create new content from simple text prompts. It can generate various types of content, including text, images, and code.'
Subjects:
- 'Machine Learning'
- 'Data Science'
Expand Down
129 changes: 129 additions & 0 deletions content/c-sharp/concepts/strings/terms/tochararray/tochararray.md
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 + " ");
}
}
}
```
66 changes: 66 additions & 0 deletions content/sql/concepts/string-function/string-function.md
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|
```

0 comments on commit 6c1d3f0

Please sign in to comment.