Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Need help with String algorithms

  1. #1
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Need help with String algorithms

    I have an assortment of information from a buffer that I need to pick apart. I have spent hours trying to figure this out, my code works but it is chunky, large, memory inefficient, and overall poor quality. I just need help utilizing existing or new algorithms to figure this out.

    This is an element from an infinite possible set and each element is organized into a structured model (see below.) How does one go about extracting a specific set of characters (the text on the lines I commented below) that have indexes that vary? The names that showed up in this example are varying and would be impossible to know beforehand.

    Goal: To return an array/list of names extracted from the data model below, for example, the perfect code would return this data.
     [dasubernoob],[steelreserve],[mutagal],[nekromight],[dontkillmi],[hiiru],[animevt],[lhavewarts],[darkneocross],[eio]
    It should return a set of names without knowing what they are beforehand. Help me brainstorm!


    //Note that this is not java code, but a input of information that has been automatically structured.
    //The variables are the values after the colons of each object.
    {
    	{
    	"reconnectDelay": 180,
    	"dataVersion": 0,
    	"game": {
    		"passwordSet": false,
    		"spectatorsAllowed": "NONE",
    		"gameType": "NORMAL_GAME",
    		"practiceGameRewardsDisabledReasons": {
    			"array": [
    			]
    		},
    		"gameTypeConfigId": 1,
    		"gameState": "IN_PROGRESS",
    		"observers": {
    			"array": [
    			]
    		},
    		"statusOfParticipants": "1111111111",
    		"glmSecurePort": 0,
    		"id": 1174840217,
    		"teamTwo": {
    			"array": [
    				{
    					"index": 0,
    					"timeAddedToQueue": 1385589663700,
    					"accountId": 33810695,
    					"queueRating": 0,
    					"originalAccountNumber": 33810695,
    					"botDifficulty": "NONE",
    					"summonerInternalName": "dasubernoob",            //Extract out the data in quotes "dasubernoob"
    					"minor": false,
    					"partnerId": "",
    					"lastSelectedSkinIndex": 6,
    					"profileIconId": 512,
    					"rankedTeamGuest": false,
    					"teamOwner": true,
    					"summonerId": 20721375,
    					"badges": 0,
    					"pickTurn": 1,
    					"dataVersion": 1,
    					"clientInSynch": true,
    					"summonerName": "DasUberNoob",
    					"pickMode": 0,
    					"originalPlatformId": "NA",
    					"teamParticipantId": 1396213667
    				},
    				{
    					"index": 0,
    					"timeAddedToQueue": 1385589663809,
    					"accountId": 112162,
    					"queueRating": 0,
    					"originalAccountNumber": 112162,
    					"botDifficulty": "NONE",
    					"summonerInternalName": "steelreserve",              //Extract out the data in quotes "steelreserve"
    					"minor": false,
    					"partnerId": "",
    					"lastSelectedSkinIndex": 0,
    					"profileIconId": 21,
    					"rankedTeamGuest": false,
    					"teamOwner": false,
    					"summonerId": 85321,
    					"badges": 4,
    					"pickTurn": 1,
    					"dataVersion": 1,
    					"clientInSynch": true,
    					"summonerName": "Steel Reserve",
    					"pickMode": 0,
    					"originalPlatformId": "NA"
    				},
    				{
    					"index": 0,
    					"timeAddedToQueue": 1385589667918,
    					"accountId": 39915078,
    					"queueRating": 0,
    					"originalAccountNumber": 39915078,
    					"botDifficulty": "NONE",
    					"summonerInternalName": "mutagal",                     //Extract out the data in quotes "mutagal"
    					"minor": false,
    					"partnerId": "",
    					"lastSelectedSkinIndex": 0,
    					"profileIconId": 28,
    					"rankedTeamGuest": false,
    					"teamOwner": false,
    					"summonerId": 25324811,
    					"badges": 0,
    					"pickTurn": 1,
    					"dataVersion": 1,
    					"clientInSynch": true,
    					"summonerName": "Mutagal",
    					"pickMode": 0,
    					"originalPlatformId": "NA",
    					"teamParticipantId": 899931864
    				},
    				{
    					"index": 0,
    					"timeAddedToQueue": 1385589667918,
    					"accountId": 37716646,
    					"queueRating": 0,
    					"originalAccountNumber": 37716646,
    					"botDifficulty": "NONE",
    					"summonerInternalName": "dontkillmi",                     //Extract out the data in quotes "dontkillmi"
    					"minor": false,
    					"partnerId": "",
    					"lastSelectedSkinIndex": 7,
    					"profileIconId": 576,
    					"rankedTeamGuest": false,
    					"teamOwner": true,
    					"summonerId": 23591328,
    					"badges": 0,
    					"pickTurn": 1,
    					"dataVersion": 1,
    					"clientInSynch": true,
    					"summonerName": "DontKillmi",
    					"pickMode": 0,
    					"originalPlatformId": "NA",
    					"teamParticipantId": 899931864
    				},
    				{
    					"index": 0,
    					"timeAddedToQueue": 1385589663700,
    					"accountId": 32224608,
    					"queueRating": 0,
    					"originalAccountNumber": 32224608,
    					"botDifficulty": "NONE",
    					"summonerInternalName": "hiiru",                     //Extract out the data in quotes "hiiru"
    					"minor": false,
    					"partnerId": "",
    					"lastSelectedSkinIndex": 0,
    					"profileIconId": 15,
    					"rankedTeamGuest": false,
    					"teamOwner": false,
    					"summonerId": 19530723,
    					"badges": 0,
    					"pickTurn": 1,
    					"dataVersion": 1,
    					"clientInSynch": true,
    					"summonerName": "Hiiru",
    					"pickMode": 0,
    					"originalPlatformId": "NA",
    					"teamParticipantId": 1396213667
    				}
    			]
    		},
    		"bannedChampions": {
    			"array": [
    			]
    		},
    		"dataVersion": 0,
    		"name": "Match-1174840217",
    		"spectatorDelay": 0,
    		"teamOne": {
    			"array": [
    				{
    					"index": 0,
    					"timeAddedToQueue": 1385589669496,
    					"accountId": 37168724,
    					"queueRating": 0,
    					"originalAccountNumber": 37168724,
    					"botDifficulty": "NONE",
    					"summonerInternalName": "eio",                     //Extract out the data in quotes "eio"
    					"minor": false,
    					"partnerId": "",
    					"lastSelectedSkinIndex": 5,
    					"profileIconId": 580,
    					"rankedTeamGuest": false,
    					"teamOwner": true,
    					"summonerId": 23158993,
    					"badges": 0,
    					"pickTurn": 1,
    					"dataVersion": 1,
    					"clientInSynch": true,
    					"summonerName": "EIo",
    					"pickMode": 0,
    					"originalPlatformId": "NA",
    					"teamParticipantId": 367099955
    				},
    				{
    					"index": 0,
    					"timeAddedToQueue": 1385589669496,
    					"accountId": 36876321,
    					"queueRating": 0,
    					"originalAccountNumber": 36876321,
    					"botDifficulty": "NONE",
    					"summonerInternalName": "lhavwarts",                //Extract out the data in quotes "lhavewarts"
    					"minor": false,
    					"partnerId": "",
    					"lastSelectedSkinIndex": 3,
    					"profileIconId": 515,
    					"rankedTeamGuest": false,
    					"teamOwner": false,
    					"summonerId": 22928062,
    					"badges": 0,
    					"pickTurn": 1,
    					"dataVersion": 1,
    					"clientInSynch": true,
    					"summonerName": "l Hav Warts",
    					"pickMode": 0,
    					"originalPlatformId": "NA",
    					"teamParticipantId": 367099955
    				},
    				{
    					"index": 0,
    					"timeAddedToQueue": 1385589665480,
    					"accountId": 203071518,
    					"queueRating": 0,
    					"originalAccountNumber": 203071518,
    					"botDifficulty": "NONE",
    					"summonerInternalName": "nekromight",                     //Extract out the data in quotes "nekromight"
    					"minor": false,
    					"partnerId": "",
    					"lastSelectedSkinIndex": 0,
    					"profileIconId": 548,
    					"rankedTeamGuest": false,
    					"teamOwner": false,
    					"summonerId": 40099514,
    					"badges": 0,
    					"pickTurn": 1,
    					"dataVersion": 1,
    					"clientInSynch": true,
    					"summonerName": "Nekromight",
    					"pickMode": 0,
    					"originalPlatformId": "NA1",
    					"teamParticipantId": 954047356
    				},
    				{
    					"index": 0,
    					"timeAddedToQueue": 1385589669496,
    					"accountId": 36707870,
    					"queueRating": 0,
    					"originalAccountNumber": 36707870,
    					"botDifficulty": "NONE",
    					"summonerInternalName": "darkneocross",              //Extract out the data in quotes "darkneocross"
    					"minor": false,
    					"partnerId": "",
    					"lastSelectedSkinIndex": 0,
    					"profileIconId": 584,
    					"rankedTeamGuest": false,
    					"teamOwner": false,
    					"summonerId": 22793922,
    					"badges": 0,
    					"pickTurn": 1,
    					"dataVersion": 1,
    					"clientInSynch": true,
    					"summonerName": "Darkneocross",
    					"pickMode": 0,
    					"originalPlatformId": "NA",
    					"teamParticipantId": 367099955
    				},
    				{
    					"index": 0,
    					"timeAddedToQueue": 1385589665480,
    					"accountId": 49312188,
    					"queueRating": 0,
    					"originalAccountNumber": 49312188,
    					"botDifficulty": "NONE",
    					"summonerInternalName": "animevt",                     //Extract out the data in quotes "animevt"
    					"minor": false,
    					"partnerId": "",
    					"lastSelectedSkinIndex": 0,
    					"profileIconId": 19,
    					"rankedTeamGuest": false,
    					"teamOwner": true,
    					"summonerId": 34940920,
    					"badges": 0,
    					"pickTurn": 1,
    					"dataVersion": 1,
    					"clientInSynch": true,
    					"summonerName": "animevt",
    					"pickMode": 0,
    					"originalPlatformId": "NA1",
    					"teamParticipantId": 954047356
    				}
    			]
    		},
    		"terminatedCondition": "NOT_TERMINATED",
    		"queueTypeName": "NORMAL",
    		"glmPort": 0,
    		"optimisticLock": 70,
    		"roomPassword": "nFvV8IU5xGxnV740",
    		"maxNumPlayers": 10,
    		"queuePosition": 0,
    		"terminatedConditionString": "NOT_TERMINATED",
    		"expiryTime": 0,
    		"gameMode": "CLASSIC",
    		"mapId": 1,
    		"gameStateString": "IN_PROGRESS",
    		"pickTurn": 3,
    		"playerChampionSelections": {
    			"array": [
    				{
    					"dataVersion": 0,
    					"summonerInternalName": "mutagal",
    					"spell2Id": 14,
    					"selectedSkinIndex": 0,
    					"championId": 79,
    					"spell1Id": 4
    				},
    				{
    					"dataVersion": 0,
    					"summonerInternalName": "nekromight",
    					"spell2Id": 11,
    					"selectedSkinIndex": 0,
    					"championId": 59,
    					"spell1Id": 4
    				},
    				{
    					"dataVersion": 0,
    					"summonerInternalName": "hiiru",
    					"spell2Id": 4,
    					"selectedSkinIndex": 0,
    					"championId": 222,
    					"spell1Id": 21
    				},
    				{
    					"dataVersion": 0,
    					"summonerInternalName": "dontkillmi",
    					"spell2Id": 4,
    					"selectedSkinIndex": 0,
    					"championId": 4,
    					"spell1Id": 14
    				},
    				{
    					"dataVersion": 0,
    					"summonerInternalName": "animevt",
    					"spell2Id": 4,
    					"selectedSkinIndex": 0,
    					"championId": 115,
    					"spell1Id": 14
    				},
    				{
    					"dataVersion": 0,
    					"summonerInternalName": "lhavwarts",
    					"spell2Id": 21,
    					"selectedSkinIndex": 0,
    					"championId": 67,
    					"spell1Id": 4
    				},
    				{
    					"dataVersion": 0,
    					"summonerInternalName": "darkneocross",
    					"spell2Id": 4,
    					"selectedSkinIndex": 0,
    					"championId": 40,
    					"spell1Id": 3
    				},
    				{
    					"dataVersion": 0,
    					"summonerInternalName": "eio",
    					"spell2Id": 6,
    					"selectedSkinIndex": 0,
    					"championId": 75,
    					"spell1Id": 12
    				},
    				{
    					"dataVersion": 0,
    					"summonerInternalName": "steelreserve",
    					"spell2Id": 11,
    					"selectedSkinIndex": 0,
    					"championId": 5,
    					"spell1Id": 4
    				},
    				{
    					"dataVersion": 0,
    					"summonerInternalName": "dasubernoob",
    					"spell2Id": 14,
    					"selectedSkinIndex": 6,
    					"championId": 58,
    					"spell1Id": 4
    				}
    			]
    		},
    		"joinTimerDuration": 12
    	},
    	"gameName": "match-1174840217",
    	"playerCredentials": {
    		"observerServerIp": "216.133.234.17",
    		"playerId": 37168724,
    		"dataVersion": 0,
    		"serverPort": 0,
    		"gameId": 1174840217,
    		"lastSelectedSkinIndex": 0,
    		"observerServerPort": 8088,
    		"observerEncryptionKey": "0GVI3+oCQVqDOcabsZm85jTRwvOpqPjQ",
    		"championId": 0,
    		"observer": true,
    		"summonerId": 0
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need help with String algorithms

    How does one go about extracting a specific set of characters (the text on the lines I commented below) from variable starting indexes?
    Can you post a simple example? Show the input String and the desire set of characters you want to extract from that String.

    What are "variable starting indexes" and how are they supposed to be used?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Need help with String algorithms

    Example: The input is the entire entity of data inside the code tags. So if I wanted to extract only [variableNameHere] from this piece of data. The set of characters I desire are after "summonerInternalName:" " and before the last" So I do know how to extract that data properly.

    "summonerInternalName:" "variableNameHere"

    As for the "variable starting indexes", I mean to say that the indexes of the characters and strings from multiple inputs would vary, and would not remain constant. For example, "passwordSet": false, from the input above starts at index 57 when in a string. However, other inputs would have different starting indexes, such as 56, 55, 54 but would have the same template data: "passwordSet": false,

  4. #4
    Member
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    70
    My Mood
    Cool
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default Re: Need help with String algorithms

    Why don't you use ResourceBundle as in your case its mostly key value pairs. In that way its easy to access either key (left side) or value (right side).

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need help with String algorithms

    Does the input data consists of records or lines with each line consisting of two parts with each part surrounded by "s? The desired part is the second part. Given this line:
    "first part" "second part here"
    The desired part is: second part here
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Need help with String algorithms

    Oh ... pretty. Your data is JSON. There are several libraries available for JSON serialization/deserialization in Java. I recommend Gson (Google's JSON API).

    My advice would be to experiment with the JSONReader to parse through all values and then begin constructing a matching data model.

    It will take some work but once you have object constructors that match the data your code will be neat, concise and very efficient. As an added bonus you will be able to reliably serialize new data with a single LOC.

  7. The Following User Says Thank You to ChristopherLowe For This Useful Post:

    Zyrion (December 6th, 2013)

  8. #7
    Member Zyrion's Avatar
    Join Date
    Feb 2013
    Location
    Iowa
    Posts
    106
    My Mood
    Angelic
    Thanks
    2
    Thanked 8 Times in 8 Posts

    Default Re: Need help with String algorithms

    THANK YOU!

Similar Threads

  1. crowssword algorithms ??
    By bady2050 in forum Algorithms & Recursion
    Replies: 0
    Last Post: May 7th, 2012, 09:15 AM
  2. Algorithms required
    By beginner in forum Member Introductions
    Replies: 1
    Last Post: February 20th, 2012, 07:42 AM
  3. Re: Sorting Algorithms
    By shashiwagh in forum Java Theory & Questions
    Replies: 1
    Last Post: March 23rd, 2011, 02:19 PM
  4. Threaded algorithms
    By TerTer in forum Algorithms & Recursion
    Replies: 0
    Last Post: April 20th, 2010, 08:34 AM
  5. Sorting Algorithms
    By Dalisra in forum Java Programming Tutorials
    Replies: 1
    Last Post: November 10th, 2009, 09:24 PM