I have a TArray which contains integers in string format. I’m trying to use the find function of FString to search for a string of integers to find the matching numbers. The find function is supposed to put out a index to the indice where the item is found but I keep getting -1. I know the string I’m searching for is in the TArray
Can I just plug a FString into the find function the way I’m doing? In the documentation it shows it being used like this.
cell.neighborA = FaceIds.Find(TEXT("some text to search for"));
The problem I have with that is I need to be able to plug this FString in, and I don’t know how to format it into the TEXT way. I know In some functions that use TEXT you can format it by doing this ("%s"), anFString. Even when I try and use the TEXT way and just search for a block of text I know exists it still returns -1.
Okay so I think I’ve figured out what is going on. it’s search each indice to see if the entire string matches my search criteria. My search criteria is only a small part of the string on each indice. So how would one go about searching within a single string? For instance, if I have a string that houses the following
1 57 93
How would I search this indice of the array to match the following
The idea is that I have an array of strings that I’ve parsed in from txt file. They are stored in faceIds (TArray). This list has vertex assignments that makeup a triangle. each triangle is one indice in the array. So I break the Fstring into 3 temporary smaller strings called x, y, z. It’s broken into the strings by finding the space " " inbetween the string numbers. Then I want to search by the length of the list “NumberOfTriangles” for each triangles 3 neighbors. A, B, and C. The triangles are created counter-clockwise, which means the neighbors should have the same vertex reference numbers only inverted. This is why I combine (y + " " + x), (z + " " + y), and (x + " " + z). I’m trying to recombine the Fstrings backwards and query the TArray to find which indices contain the 3 different neighbors. They are all triangles so there should be 3 exactly for the total NumberOfTriangles.
Okay so I’ve tried to rework it to look more like your approach. Am I understanding the for loop you put down? does “auto s : FaceIds” automatically shuffle through the length of the array and assign each indice to “s”?
//Discover the neighbors
void AWorldCell::establishNeighbors()
{
FWorldCells cell;
FString vrtxSpaces, strTempA, strTempB, x, y, z;
vrtxSpaces = " ";
int faceIndx = 0;
for (int i = 0; i < NumberOfTriangles; i++)
{
//Split the string face ids into parts
strTempA = FaceIds[i];
strTempA.Split(vrtxSpaces, &x, &y, ESearchCase::CaseSensitive, ESearchDir::FromStart);
strTempB = y;
strTempB.Split(vrtxSpaces, &y, &z, ESearchCase::CaseSensitive, ESearchDir::FromStart);
//Three loops that find faces shared edge partner face id and store it in cell.neighborA, B, C
for (auto s : FaceIds)
{
if (s.Contains(y + " " + x))
{
cell.neighborA = faceIndx;
}
faceIndx++;
}
faceIndx = 0;
for (auto s : FaceIds)
{
if (s.Contains(z + " " + y))
{
cell.neighborB = faceIndx;
}
faceIndx++;
}
faceIndx = 0;
for (auto s : FaceIds)
{
if (s.Contains(x + " " + z))
{
cell.neighborB = faceIndx;
}
faceIndx++;
}
faceIndx = 0;
neighborList.Add(cell);
}
}
Bah, my logic was all wrong. z + x would not work. They’re never side by side backwards like that. So, to get around this I decided to parse the face id list in one group of numbers at a time. Then compare them in sets of three. Anyhow, heres the code…
//Discover the neighbors
void AWorldCell::establishNeighbors()
{
FWorldCells cell;
FString x, y, z;
for (int i = 0; i < NumberOfTriangles * 3; i += 3)
{
//Split the string face ids into parts
x = FaceIds[i];
y = FaceIds[i+1];
z = FaceIds[i+2];
//Three different edges evaluations to look for
for (int j = 0; j < NumberOfTriangles * 3; j += 3)
{
if (FaceIds[j] == z && FaceIds[j + 1] == y)
{
cell.neighborA = j / 3;
}
if (FaceIds[j] == z && FaceIds[j + 2] == x)
{
cell.neighborB = j / 3;
}
if (FaceIds[j+1] == y && FaceIds[j+2] == x)
{
cell.neighborC = j / 3;
}
}
neighborList.Add(cell);
}
}