public void Copy(QR_CODE_DATA data){ shelf = data.shelf; minPlayers = data.minPlayers; maxPlayers = data.maxPlayers; name = data.name; rating = data.rating; type = data.type; minutes = data.minutes; difficulty = data.difficulty; }
public static QR_CODE_DATA StripQrCodeV1(string code){ int lastIndex = 0, nextIndex = 0; QR_CODE_DATA data = new QR_CODE_DATA (); //find shelf number string lastSearch = "Shelf #", nextSearch = ", "; lastIndex = code.IndexOf(lastSearch) + lastSearch.Length; //We want the index at the end of this string nextIndex = code.IndexOf(nextSearch,lastIndex); //We want the index at the start of this string if(!int.TryParse(code.Substring(lastIndex,nextIndex - lastIndex),out data.shelf)){ //We will use null and -1 as our defaults. data.shelf = -1; } //fix indexes and find name lastIndex = nextIndex + nextSearch.Length; nextSearch = ", "; nextIndex = code.IndexOf(nextSearch,lastIndex); data.name = code.Substring(lastIndex,nextIndex - lastIndex); //fix indexes and find rating lastIndex = nextIndex + nextSearch.Length; nextSearch = ", "; nextIndex = code.IndexOf(nextSearch,lastIndex); data.rating = code.Substring(lastIndex,nextIndex - lastIndex); //fix indexes and find type lastIndex = nextIndex + nextSearch.Length; nextSearch = ", "; nextIndex = code.IndexOf(nextSearch,lastIndex); data.type = code.Substring(lastIndex,nextIndex - lastIndex); //fix indexes and find minPlayers lastIndex = nextIndex + nextSearch.Length; nextSearch = " - "; nextIndex = code.IndexOf(nextSearch,lastIndex); if(!int.TryParse(code.Substring(lastIndex,nextIndex - lastIndex),out data.minPlayers)){ //We will use null and -1 as our defaults. data.minPlayers = -1; } //fix indexes and find maxPlayers lastIndex = nextIndex + nextSearch.Length; nextSearch = ", "; nextIndex = code.IndexOf(nextSearch,lastIndex); if(!int.TryParse(code.Substring(lastIndex,nextIndex - lastIndex),out data.maxPlayers)){ //We will use null and -1 as our defaults. data.maxPlayers = -1; } //fix indexes and find minutes lastIndex = nextIndex + nextSearch.Length; nextSearch = " minutes, "; nextIndex = code.IndexOf(nextSearch,lastIndex); data.minutes = code.Substring(lastIndex,nextIndex - lastIndex); //fix indexes and find difficulty lastIndex = nextIndex + nextSearch.Length; nextSearch = " to learn"; nextIndex = code.IndexOf(nextSearch,lastIndex); data.difficulty = code.Substring(lastIndex,nextIndex - lastIndex); return data; }
public static bool TryParseQrCodeV1(string code, out QR_CODE_DATA data){ data = new QR_CODE_DATA (); if (IsValidQrCodeV1 (code)) { data.Copy(StripQrCodeV1 (code)); return true; } else { return false; } }