C
C#2y ago
FSHF

clone

Instead of removing last number i would like to clone, how?
private void btnpocl(object sender, EventArgs e)
{

if (ccal.Length > 0)
{
ccal = ccal.Remove(ccal.Length - 1, 1);
}

txtbout.Text = ccal;
}
private void btnpocl(object sender, EventArgs e)
{

if (ccal.Length > 0)
{
ccal = ccal.Remove(ccal.Length - 1, 1);
}

txtbout.Text = ccal;
}
44 Replies
JakenVeina
JakenVeina2y ago
huh?
FSHF
FSHFOP2y ago
this function remove last symbol in my string, instead i would like to clone it / copy the last symbol of string. How can i do that?
JakenVeina
JakenVeina2y ago
what do you mean "clone it/copy it?
FSHF
FSHFOP2y ago
i want to use the last symbol again for ekvation f.e lastnumber - 5
JakenVeina
JakenVeina2y ago
so
Pobiega
Pobiega2y ago
ccal is a string here, right?
JakenVeina
JakenVeina2y ago
var lastCharacter = ccal[^0];
var lastCharacter = ccal[^0];
?
FSHF
FSHFOP2y ago
yes
Pobiega
Pobiega2y ago
var last = ccal[^1]; ^1 is correct
JakenVeina
JakenVeina2y ago
is it ^1 or ^0? k
Pobiega
Pobiega2y ago
^0 is oob
JakenVeina
JakenVeina2y ago
I've had virtually 0 opportunity to use that syntax since it was added
MODiX
MODiX2y ago
Pobiega#2671
REPL Result: Success
"12345"[^1]
"12345"[^1]
Result: char
5
5
Compile: 461.186ms | Execution: 38.873ms | React with ❌ to remove this embed.
JakenVeina
JakenVeina2y ago
"clone" and "copy" are very much not the words to use for this
FSHF
FSHFOP2y ago
im getting red under ^1
Pobiega
Pobiega2y ago
are you using an old .NET version?
FSHF
FSHFOP2y ago
the latest nvm
Pobiega
Pobiega2y ago
You could still have picked .net framework during project creation, even if you made it a day ago.
FSHF
FSHFOP2y ago
whats the latest?
Pobiega
Pobiega2y ago
.NET 7
FSHF
FSHFOP2y ago
how do i check
Pobiega
Pobiega2y ago
open your .csproj file
FSHF
FSHFOP2y ago
CS8370 Feature 'index operator' is not available in C# 7.3. Please use language version 8.0 or greater. C
Pobiega
Pobiega2y ago
Yeah you are 100% using .net framework.
FSHF
FSHFOP2y ago
thats the error code i got, cant find my .csproj
Pobiega
Pobiega2y ago
are you using visual studio 2022?
FSHF
FSHFOP2y ago
yes
Pobiega
Pobiega2y ago
$newproject
MODiX
MODiX2y ago
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework. .NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended. https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
Pobiega
Pobiega2y ago
you picked one of the "NO" options
FSHF
FSHFOP2y ago
is there a solution to it
Pobiega
Pobiega2y ago
Create a new project and copy your stuff over most of it will likely work with little changes, since its a new project and you are still a beginner
FSHF
FSHFOP2y ago
will try
FSHF
FSHFOP2y ago
Does it matter which i choose
Pobiega
Pobiega2y ago
6 .net 6
FSHF
FSHFOP2y ago
can i just copy and paste over the folder and files for it to work?
Pobiega
Pobiega2y ago
no only the .cs files
FSHF
FSHFOP2y ago
ok
var lccal = ccal[^1];
double ans = Math.Pow(lccal, 2);
ccal += ans.ToString();
var lccal = ccal[^1];
double ans = Math.Pow(lccal, 2);
ccal += ans.ToString();
would this be right for doing power of 2 on the last number
Pobiega
Pobiega2y ago
no because llcal will be a char
FSHF
FSHFOP2y ago
is there a way to remove first instead of last?
TheRanger
TheRanger2y ago
remove or copy?
FSHF
FSHFOP2y ago
i got ^2 working but i need to remove when i 5^2 i get 525 because i havent removed 5
TheRanger
TheRanger2y ago
? can u elaborate
FSHF
FSHFOP2y ago
nvm got it working, thx
Want results from more Discord servers?
Add your server