C
C#13mo ago
Mekasu0124

❔ ✅ get unknown range of list to display?

internal record Evidence(string Name)
{
public static Evidence None = new Evidence("None");
public static Evidence Emf5 = new Evidence("EMF 5");
public static Evidence SpiritBox = new Evidence("Spirit Box");
public static Evidence Writing = new Evidence("Ghost Writing");
public static Evidence Dots = new Evidence("DOTs Projector");
public static Evidence Ultraviolet = new Evidence("Ultraviolet");
public static Evidence Freezing = new Evidence("Freezing Temperatures");
public static Evidence GhostOrbs = new Evidence("Ghost Orbs");

public override string ToString() => Name;
}
internal record Evidence(string Name)
{
public static Evidence None = new Evidence("None");
public static Evidence Emf5 = new Evidence("EMF 5");
public static Evidence SpiritBox = new Evidence("Spirit Box");
public static Evidence Writing = new Evidence("Ghost Writing");
public static Evidence Dots = new Evidence("DOTs Projector");
public static Evidence Ultraviolet = new Evidence("Ultraviolet");
public static Evidence Freezing = new Evidence("Freezing Temperatures");
public static Evidence GhostOrbs = new Evidence("Ghost Orbs");

public override string ToString() => Name;
}
this information is generated into a string like string evidence = "EMF 5, Spirit Box, Ghost Writing";. Knowing that it's not the same evidence every time, how can I cut off the last piece of evidence and display the first two?
33 Replies
Pobiega
Pobiega13mo ago
split the string on , and drop the last item?
Mekasu0124
Mekasu012413mo ago
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence).Split(", ")[0];
string evidenceOne = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence).Split(", ")[1];
string evidnce = evidenceZero + evidenceOne;
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence).Split(", ")[0];
string evidenceOne = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence).Split(", ")[1];
string evidnce = evidenceZero + evidenceOne;
like this?
Pobiega
Pobiega13mo ago
ugh, no
Mekasu0124
Mekasu012413mo ago
well this is how it's generated into a string....
Pobiega
Pobiega13mo ago
well if you already have it as an array, isnt it better to just use the array then? why convert to string, remove the last item, then convert back into array, to then convert to string again? that seems insanely convoluted 😄
Mekasu0124
Mekasu012413mo ago
idk that's why I asked. This isn't python so it's confusing.....sorry. I don't mean to disappoint
Pobiega
Pobiega13mo ago
so, this is an X Y problem you're trying to solve X, your attempted solution is Y, so you're asking about Y I need you to tell me about X what is the actual problem you are trying to solve here?
Mekasu0124
Mekasu012413mo ago
ok you said it's already an array
Pobiega
Pobiega13mo ago
ghost.Evidence is, last time we talked so if you have access to that, its much easier to work with that directly
Mekasu0124
Mekasu012413mo ago
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence[0]);
string evidenceOne = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence[1]);
string evidence = evidenceZero + evidenceOne;
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence[0]);
string evidenceOne = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence[1]);
string evidence = evidenceZero + evidenceOne;
so I should be able to do something like this then, right?
Pobiega
Pobiega13mo ago
rather than the string version uhm.. what do you think string.Join does?
Mekasu0124
Mekasu012413mo ago
joins an array to a string that's why I'm trying to index the array
Pobiega
Pobiega13mo ago
right. and ghost.Evidence is an array, that we agree on what is ghost.Evidence[0] thou? is that also an array?
Mekasu0124
Mekasu012413mo ago
internal class Ghost
{
public required string Name { get; init; }
public required string NormalizedName { get; set; }
public required string Description { get; set; }
public required string Weakness { get; set; }
public required string Strength { get; set; }
public required Evidence[] Evidence { get; set; }
public required HuntSanity Sanity { get; set; }
public required Speed Speed { get; set; }
public required Tell[] Tells { get; set; }
public required Behavior[] Behaviors { get; set; }
public required HuntSanityBehavior[] HuntSanityBehaviors { get; set; }
public required HuntSpeedBehavior[] HuntSpeedBehaviors { get; set; }
public required Evidence[] GuaranteedEvidence { get; set; }
}
internal class Ghost
{
public required string Name { get; init; }
public required string NormalizedName { get; set; }
public required string Description { get; set; }
public required string Weakness { get; set; }
public required string Strength { get; set; }
public required Evidence[] Evidence { get; set; }
public required HuntSanity Sanity { get; set; }
public required Speed Speed { get; set; }
public required Tell[] Tells { get; set; }
public required Behavior[] Behaviors { get; set; }
public required HuntSanityBehavior[] HuntSanityBehaviors { get; set; }
public required HuntSpeedBehavior[] HuntSpeedBehaviors { get; set; }
public required Evidence[] GuaranteedEvidence { get; set; }
}
in the ghost model, it is done as an array.
"Evidence": [
{
"Name": "EMF 5"
},
{
"Name": "Spirit Box"
},
{
"Name": "Ghost Writing"
}
],
"Evidence": [
{
"Name": "EMF 5"
},
{
"Name": "Spirit Box"
},
{
"Name": "Ghost Writing"
}
],
then it's stored to the json file like so. When I pull it from the json file,
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence))
string evidenceZero = string.Join(", ", (IEnumerable<Evidence>)ghost.Evidence))
I do so like this to get it into a string that looks like "EMF 5, Spirit Box, Ghost Writing" so it's easier to print to the screen. I'm just trying to figure out how to drop the last item in the string
Pobiega
Pobiega13mo ago
but why in the string? isnt the string literally just a display interpretation of the array? you shouldn't be modifying the string, you should be modifying the array and honestly, at that point, it shouldn't be an array, it should be a list you're still focused on Y tell me about X. why do you want to drop the last item from the string?
Want results from more Discord servers?
Add your server