yourFriend
yourFriend
CC#
Created by yourFriend on 4/18/2025 in #help
Silly OOP question about constructors
No description
7 replies
CC#
Created by yourFriend on 4/10/2025 in #help
Help with understanding this logic question.
After 1 pm sonething went wrong with the mechanism of a certain clock and at 1.30 pm it struck 2 hours. Then went on striking every half an hour in the routine way indicating wrong hours. Find out when did it strike the correct hour next? (A) 12.30 am (B) 11 pm (C) 6.30 pm (D) Never
Answer (A) 12.30 am Problem I don't understand what struck 2 hours means? Also what striking every half an hour means?
11 replies
CC#
Created by yourFriend on 4/10/2025 in #help
Regex to match text between nested tags
Question:
Write a program that extracts all the text without any tags and attribute values from an HTML document. Sample text: <html> <head><title>News</title></head> <body><p><a href="http://softuni.org">Software University</a>aims to provide free real-world practical training for young people who want to turn into skillful software engineers.</p></body> </html> Sample result: News Software University aims to provide free real-world practical training for young people who want to turn into skillful software engineers.
I solved it without using Regex. Here's the code: https://paste.mod.gg/orqiwpelwkzq/0 But I was wondering what the regex pattern would look like for matching text within nested tags. :catderp: I have asked similar question but it didn't involve nested tags. Link: https://discord.com/channels/143867839282020352/1358651997745709267
8 replies
CC#
Created by yourFriend on 4/9/2025 in #help
Regex help.
For Learning purposes I want to match C# in given string. But the below pattern doesn't work for C# while it works for any alphabet word.
string s = "Just a random string in C#.";

string pattern = @"(?i:\bC#\b)";
Match match = Regex.Match(s, pattern);
// Doesn't work
// I also tried:
// @"(?i:\bC\#\b)" escaping #
// @"(?i:\bC\u0023\b)" using unicode

// But same pattern works for any other alphabetical word
string pattern2 = @"(?i:\brandom\b)";
Match match2 = Regex.Match(s, pattern2);
string s = "Just a random string in C#.";

string pattern = @"(?i:\bC#\b)";
Match match = Regex.Match(s, pattern);
// Doesn't work
// I also tried:
// @"(?i:\bC\#\b)" escaping #
// @"(?i:\bC\u0023\b)" using unicode

// But same pattern works for any other alphabetical word
string pattern2 = @"(?i:\brandom\b)";
Match match2 = Regex.Match(s, pattern2);
11 replies
CC#
Created by yourFriend on 4/7/2025 in #help
✅ Need help with regular expression pattern
I am trying to match everything between two given tags using regular expression. For example:
string s = "We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.";
string startTag = "<upcase>";
string endTag = "</upcase>";

// I want it to match:
// 1. <upcase>yellow submarine</upcase>
// 2. <upcase>anything</upcase>

// This pattern match nothing
string pattern = $@"(?'startTag'\s*{startTag})" + $@"(?'text'.*(?!{endTag}))" + $@"(?'endTag'{endTag})";

// This pattern match till last endTag instead for first endTag after the startTag:
// 1. <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase>
string pattern = $@"(?'startTag'\s*{startTag})" + $@"(?'text'.*)" + $@"(?'endTag'{endTag})";

MatchCollection matches = Regex.Matches(s, pattern);
string s = "We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.";
string startTag = "<upcase>";
string endTag = "</upcase>";

// I want it to match:
// 1. <upcase>yellow submarine</upcase>
// 2. <upcase>anything</upcase>

// This pattern match nothing
string pattern = $@"(?'startTag'\s*{startTag})" + $@"(?'text'.*(?!{endTag}))" + $@"(?'endTag'{endTag})";

// This pattern match till last endTag instead for first endTag after the startTag:
// 1. <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase>
string pattern = $@"(?'startTag'\s*{startTag})" + $@"(?'text'.*)" + $@"(?'endTag'{endTag})";

MatchCollection matches = Regex.Matches(s, pattern);
13 replies
CC#
Created by yourFriend on 4/5/2025 in #help
Is it possible to reverse a string letter by letter using only regular expression?
I am learning string manipulation. Learned a bit about string and StringBuilder. Now onto Regex and I'm trying to do everything which I do with string methods and StringBuilder methods by using Regex alone for learning purposes. But reversing a string letter by letter seems pretty hard by just Regex.Replace(intialString, pattern, replacement) I guess pattern can be:
string pattern = "."; // Match every character except new line
string pattern = "."; // Match every character except new line
But how to replace it initialString[len - i - 1] with initialString[i] character of the string initialString?
5 replies
CC#
Created by yourFriend on 4/1/2025 in #help
✅ *"Converting possible null value to non nullable type"* warning in `Console.ReadLine()`
No description
8 replies
CC#
Created by yourFriend on 3/30/2025 in #help
Error acquiring .NET when offline but works when online in VS Code
No description
5 replies
CC#
Created by yourFriend on 3/28/2025 in #help
In String constructor `String(Char*)`, `Char*` is character pointer or character array pointer?
No description
18 replies
CC#
Created by yourFriend on 3/17/2025 in #help
Book question. Explain this solution of Subset Sum problem.
Code: https://paste.mod.gg/hqxraqfhdgeg/0 Copy/pasted from last solution here: https://www.geeksforgeeks.org/subset-sum-problem-dp-25/ But I don't understand it. I want to understand what, why and how. My solution was to generate all combinations without repetition but its obviously very slow.
2 replies
CC#
Created by yourFriend on 3/14/2025 in #help
How to install dotnet runtime and sdks on debian virtual machine?
This should be simple like: 1. Add appropriate repository 2. Then sudo apt install But I'm not able to add repository. I tried sudo apt-add-repository https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb It shows following errors: 1. 403 Forbidden 2. 404 Not Found I'm new to linux
9 replies
CC#
Created by yourFriend on 3/5/2025 in #help
Need guidance on how to develop networks(not https) with fellow C# developers.
Hello, everyone. I'm going to start preparing seriously for job as .net full stack developer. Here's my game plan: 1. First 6 months: 1.1 Fundamentals 1.2 DSA 1.3 OOP 1.4 Asynchronous programming (optional) 1.5 Networking (optional) 2. Next 1 year: 2.1 SQL 2.2 ASP.NET Core 2.3 Some UI (haven't decided which one) . . . Haven't decided yet. 2. I have plenty of free and paid resources online. 3. Plenty of online certifications, like, w3school, MSDN, Coursera, Edx, Udemy, freeCodeCamp. hopefully they will be enough. 4. But how to develop networks with fellow devs. as I'm self studying at home and not in a university campus.
3 replies
CC#
Created by yourFriend on 3/1/2025 in #help
Is Merge Sort implementation wrong in Wikipedia?
https://en.wikipedia.org/wiki/Merge_sort In the below code: 1. iMiddle = (iEnd - iBegin) / 2 should be iMiddle = iBegin + (iEnd - iBegin) / 2 I guess. 2. In method TopDownMerge array B was sorted but never copied to array A.
// Array A[] has the items to sort; array B[] is a work array.
void TopDownMergeSort(A[], B[], n)
{
CopyArray(A, 0, n, B); // one time copy of A[] to B[]
TopDownSplitMerge(A, 0, n, B); // sort data from B[] into A[]
}

// Split A[] into 2 runs, sort both runs into B[], merge both runs from B[] to A[]
// iBegin is inclusive; iEnd is exclusive (A[iEnd] is not in the set).
void TopDownSplitMerge(B[], iBegin, iEnd, A[])
{
if (iEnd - iBegin <= 1) // if run size == 1
return; // consider it sorted
// split the run longer than 1 item into halves
iMiddle = (iEnd + iBegin) / 2; // iMiddle = mid point
// recursively sort both runs from array A[] into B[]
TopDownSplitMerge(A, iBegin, iMiddle, B); // sort the left run
TopDownSplitMerge(A, iMiddle, iEnd, B); // sort the right run
// merge the resulting runs from array B[] into A[]
TopDownMerge(B, iBegin, iMiddle, iEnd, A);
}

// Left source half is A[ iBegin:iMiddle-1].
// Right source half is A[iMiddle:iEnd-1 ].
// Result is B[ iBegin:iEnd-1 ].
void TopDownMerge(B[], iBegin, iMiddle, iEnd, A[])
{
i = iBegin, j = iMiddle;

// While there are elements in the left or right runs...
for (k = iBegin; k < iEnd; k++) {
// If left run head exists and is <= existing right run head.
if (i < iMiddle && (j >= iEnd || A[i] <= A[j])) {
B[k] = A[i];
i = i + 1;
} else {
B[k] = A[j];
j = j + 1;
}
}
}

void CopyArray(A[], iBegin, iEnd, B[])
{
for (k = iBegin; k < iEnd; k++)
B[k] = A[k];
}
// Array A[] has the items to sort; array B[] is a work array.
void TopDownMergeSort(A[], B[], n)
{
CopyArray(A, 0, n, B); // one time copy of A[] to B[]
TopDownSplitMerge(A, 0, n, B); // sort data from B[] into A[]
}

// Split A[] into 2 runs, sort both runs into B[], merge both runs from B[] to A[]
// iBegin is inclusive; iEnd is exclusive (A[iEnd] is not in the set).
void TopDownSplitMerge(B[], iBegin, iEnd, A[])
{
if (iEnd - iBegin <= 1) // if run size == 1
return; // consider it sorted
// split the run longer than 1 item into halves
iMiddle = (iEnd + iBegin) / 2; // iMiddle = mid point
// recursively sort both runs from array A[] into B[]
TopDownSplitMerge(A, iBegin, iMiddle, B); // sort the left run
TopDownSplitMerge(A, iMiddle, iEnd, B); // sort the right run
// merge the resulting runs from array B[] into A[]
TopDownMerge(B, iBegin, iMiddle, iEnd, A);
}

// Left source half is A[ iBegin:iMiddle-1].
// Right source half is A[iMiddle:iEnd-1 ].
// Result is B[ iBegin:iEnd-1 ].
void TopDownMerge(B[], iBegin, iMiddle, iEnd, A[])
{
i = iBegin, j = iMiddle;

// While there are elements in the left or right runs...
for (k = iBegin; k < iEnd; k++) {
// If left run head exists and is <= existing right run head.
if (i < iMiddle && (j >= iEnd || A[i] <= A[j])) {
B[k] = A[i];
i = i + 1;
} else {
B[k] = A[j];
j = j + 1;
}
}
}

void CopyArray(A[], iBegin, iEnd, B[])
{
for (k = iBegin; k < iEnd; k++)
B[k] = A[k];
}
10 replies
CC#
Created by yourFriend on 11/27/2024 in #help
How to stop git from tracking all a folder(.vscode) and everything inside it.
Git is init in root say RootFolder which contain multiple projects say P1, P2 and so on and each project folder has .vscode folder. I have tried this from RootFolder git rm --cached -r .vscode/ But it says fatal: pathspec '.vscode/' did not match any files However it works from parent folders i.e. P1, P2, etc. And I have got hundreds of them.
5 replies
CC#
Created by yourFriend on 11/25/2024 in #help
Do C# dev kit extension requires internet connection to work?
No description
7 replies
CC#
Created by yourFriend on 11/24/2024 in #help
How to open brace on new line by default for C# or any language in vs code?
I want this by default:
if(condition)
{
code here;
}
if(condition)
{
code here;
}
Instead of:
if(condition){
code here;
}
if(condition){
code here;
}
8 replies