C
C#10mo ago
IVIICHAELxx

How can I fetch identical strings concatenated with 1 and so on at the end through this dictionary

Basically the identical string is the entity's classname: "keyframe_rope" or "move_rope"
No description
No description
4 Replies
Doombox
Doombox10mo ago
are you looking for basically every instance of keyframe_rope_n in a dictionary where n is unknown?
var baseName = "keyframe_rope";
var searchName = baseName;
var i = 1;
while(someDictionary.TryGetValue(searchName, out var res))
{
// do something with the result here
searchName = $"{baseName}{i++}";
}
var baseName = "keyframe_rope";
var searchName = baseName;
var i = 1;
while(someDictionary.TryGetValue(searchName, out var res))
{
// do something with the result here
searchName = $"{baseName}{i++}";
}
would work with the dictionary itself and prevent you just querying every key this assumes that every index is in there with no gaps or you could do this:
foreach(var result in someDictionary.Where(x => x.Key.StartsWith("keyframe_rope"))
{
// do something with the key/value pair "result" here.
}
foreach(var result in someDictionary.Where(x => x.Key.StartsWith("keyframe_rope"))
{
// do something with the key/value pair "result" here.
}
which would just broadly get them all regardless of that, whilst being a bit easier to read :catshrug:
IVIICHAELxx
IVIICHAELxxOP10mo ago
yes I need to make it so I can identify both att0 and att1
Doombox
Doombox10mo ago
yup
foreach(var result in someDictionary.Where(x => x.Key.StartsWith("keyframe_rope"))
{
// do something with the key/value pair "result" here.
}
foreach(var result in someDictionary.Where(x => x.Key.StartsWith("keyframe_rope"))
{
// do something with the key/value pair "result" here.
}
would do that it's a little inefficient because you're doing a string comparison on the entire dictionary, but it would get everything that starts with a given name if you know 100% that att2 would only exist if att1 also definitely existed you could use the first solution I posted which would be a bit more efficient or if you know 100% that the maximum number of any instance is say 10, you could just do a query for all 10 in a for loop, which may or may not be a bit more efficient too, ymmv
IVIICHAELxx
IVIICHAELxxOP10mo ago
I'm only doing this because roblox has trouble identifying things if they aren't named a specific name this should work would this work?
foreach(var att0 in someDictionary.Where(x => x.Key.StartsWith("keyframe_rope"))
{
// do something with the key/value pair "result" here.
}
foreach(var att0 in someDictionary.Where(x => x.Key.StartsWith("keyframe_rope"))
{
// do something with the key/value pair "result" here.
}
foreach(var att1 in someDictionary.Where(x => x.Key.StartsWith("keyframe_rope"))
{
// do something with the key/value pair "result" here.
}
foreach(var att1 in someDictionary.Where(x => x.Key.StartsWith("keyframe_rope"))
{
// do something with the key/value pair "result" here.
}
Want results from more Discord servers?
Add your server