Looping Through Array Of Characters

How you would go about looping through an array of characters within a string and replacing them with a “-” if they do not exsist in another array (an array of characters that the character knows at this point in the game).

Hey @Bazz2498x! Welcome to the forums!

What I believe you are looking for is “Get Character Array from String”. Check out this non-Epic affiliated overview with an example of how to use it:

I hope the above is the solution you need!

Hi, thank you for this, but how do I replace the characters to another letter? For example, if I loop through the array of characters and find a letter that the player character does not know, then I want to replace it with “-”.

Hey @Bazz2498x!

If you are just wanting to replace letters, it may make more sense to use the replace node or replace inline node. This will streamline that process so instead of creating an an array like displayed above, it will simply loop through the string and replace the letters you are looking for. The advantage here is that you can also choose to do words, phrases, etc. as what you want to replace. Check out this example using a string where all the A’s will be replaced with “-”:

UnrealEditor_ii8xY6i2sr

Doing it this way also has the advantage of letting you preserve your original string, so you can re-remove characters the player does not know if they learn a new one.

I hope the above is the solution you are looking for.

How do I go about doing this for multiple letters in the string?

Hey @Bazz2498x!

There are a few ways you could go about this. Here is a very quick example (not necessarily the best or most optimized example) of how you could do multiple letters. In this example using the same string, both a and e are ‘unknown’ while d is learned:

UnrealEditor_dZDLTS6kmu

Thank you for this! Would you be able to do this via a for loop?

WDYM? The function for “Replace” already loops through the string you dont need to loop.
If you mean looping over your characters then just use Quetzalcodename answer in a loop if you want.

For an array of characters

You can just

Hey @Bazz2498x!

Absolutely! With a little bit of tweaking to what @marister explained above, you can easily have this also check whether or not a letter is learned so you can specify which letters you want removed using a map variable. Note, you will still need the character array. Check out this example that returns the same results as before:

image

I hope the above is the solution you need!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.