How to remove interior faces while keeping exterior faces untouched?

Thank you for the awesome materials examples. @hofk How would you convert a simple dungeon array to your more intricate array that you have made above in an earlier example? Trying to figure out how to make a function that would say, if i encounter a “X” that has another “X” before and after it but not above or below then I know I need to convert that “X” to a “:” to represent that it must be part of a hall. Do you know how I would go about doing that? Thanks.

How to make function to convert from:

"xxxxxxxxx"
"x       x"
"x   x   x"
"x       x"
"xxxxxxxxx"

To:

"F:::::::7"
"H       H"
"H   G   H"
"H       H"
"L:::::::J"