So I have a program that needs to get a string thats in a string and between two points {
and }
I am using the code
public string findTopic(string sourceString, string topicName)
{
//Finds the point where the topic name is and cuts everything off infront of it.
int t1 = sourceString.IndexOf(topicName);
string before = sourceString.Substring(0, t1);
//Finds the { that opens the topic
int tstart = before.LastIndexOf("{");
//Finds the end of the topic
string after = sourceString.Substring(t1);
//Finds the } that closes the topic
int tend = after.IndexOf("}");
string topic = sourceString.Substring(tstart, tend - tstart);
Console.WriteLine(before);
Console.WriteLine(after);
Console.WriteLine(t1.ToString());
Console.WriteLine(tstart.ToString());
Console.WriteLine(tend.ToString());
Console.WriteLine("Topic Found = " + topic);
return topic;
}
This gives me only {
It is going through a string that looks like this
var Ultimate_Mod_Maker_Mod = {};
(function () {
//Made_with_Ultimate_Mod_Maker
Ultimate_Mod_Maker_Mod.addTopic = function () {
GDT.addTopics([
{
id: "4235-1405-1469-567-4280",//ID
name: "Random Topic".localize("game topic"),//Name
genreWeightings: [0.9, 0.9, 0.9, 0.9, 0.9, 0.9],//Genre
audienceWeightings: [0.9, 0.9, 0.9]//Audience
},
]);
};
Ultimate_Mod_Maker_Mod.addPlatform = function () {
GDT.addPlatforms([
]);
};
})();
And it is suppose to find the a topic. In this case the name is "Random Topic" It is suppose to get this string from that string by finding the name of the topic:
{
id: "4235-1405-1469-567-4280",//ID
name: "Random Topic".localize("game topic"),//Name
genreWeightings: [0.9, 0.9, 0.9, 0.9, 0.9, 0.9],//Genre
audienceWeightings: [0.9, 0.9, 0.9]//Audience
},
But all it returns is {
What am I doing wrong?
Edit: This program creates mods for games, so there are multiple copies of the
{
id: "4235-1405-1469-567-4280",//ID
name: "Random Topic".localize("game topic"),//Name
genreWeightings: [0.9, 0.9, 0.9, 0.9, 0.9, 0.9],//Genre
audienceWeightings: [0.9, 0.9, 0.9]//Audience
},
I have to be able to sort through them. If you think about it thats why I have the topic name in the method.