Daniel Lip
Daniel Lip

Reputation: 11321

How can i extract specific string from a text?

I have a file that i edit with notepad, example of some of the file content :

ionTrigger_1_Deactivated":false,"bWL1TwoSwitchesArrived":true,"E1_WL1_HangingBedsA_M.TheWorld:PersistentLevel.GppInteractionTrigger_0_Deactivated":false,"E1_WL1_HangingBedsA_M.TheWorld:PersistentLevel.GppInteractionTrigger_1_Deactivated":false,"bHangingBedsASaved":true} ! m_WhatLevelPlayerIsAtEncodedJson  ArrayProperty T L {"currentLevelName":"E1_WL1_HangingBedsA_M","currentLevelEntryDirection":8} & m_WhatCheckPointPlayerIsAtEncodedJson  ArrayProperty { s {"hasCheckPoint":true,"LocX":19873.1816,"LocY":2330.6631,"LocZ":-299.1126,"RotPitch":0,"RotYaw":81508,"RotRoll":0} None m_SubtitlesDisplayed BoolProperty None

what i want to extract as a string is this part :

currentLevelName":"E1_WL1_HangingBedsA_M"

the problems are how to extract it and that in each file the currentLevelName is different. in this file the currentLevelName is E1_WL1_HangingBedsA_M but in another file for example the name is : E1_WL1_HallwayDragonFace_M

i want to loop over all the files and in each file to extract that part. and when extracting the currentLevelName i want to change the current file name to that level name for example if the first file in the loop is : savedGame001

then in the loop the first file name should be renamed to : Current Level Name_E1_WL1_HangingBedsA_M

Upvotes: 0

Views: 56

Answers (1)

Rezo Megrelidze
Rezo Megrelidze

Reputation: 3060

If the text in your file is in JSON format i suggest use the Newtonsoft.Json package from nuget. You can deserialize the json to a dynamic object using

dynamic myJsonObject = JsonConvert.DeserializeObject("filename.json");

Upvotes: 1

Related Questions