Apologies for how basic this question is.
I’m a 3D modeller and animator, not a programmer but need to write a simple programme as part of some research.
This code works.
foreach (Transform letter in markers)
{
Debug.Log(“Letter=” + letter);
}
I just need to remove the end of the transform letter. The length of the transform will change. I want to keep the first letter only.
Thank you.
I just need to remove the end of the string letter. The length of the string will change. I want to keep the first letter only.
The 0 is where it starts and the 1 is how many to remove.
stringVariable= value.Substring(0, stringVariable.Length - 1);
If you only need the 1st letter you can use markers[0] to get the 1st letter and leave the string unchanged.
As the other 2 answers kind of miss some things in your code, here we go with a third one:
You might want to check what you are doing in your code.
You are iterating (looping) over a List or Array called markers
. The variable type of letter
is not string
but Transform
. Assuming that you want to have the first letter of the name of the object you need this:
foreach (Transform letter in markers) {
var firstLetter = letter.name[0].ToString();
Debug.Log($"Letter object is of type Transform but it's name is {letter.name} with the first letter of the name being {firstLetter}");
}
The ToString()
is a recommendation as taking one index of a string results in a char
variable and not a string
.
let me know if that helped…