dcsimg
Results 1 to 10 of 10

Thread: Very difficult string manipulate due to company stupidity

  1. #1

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,611

    Very difficult string manipulate due to company stupidity

    Hi.
    I am getting a string of seats that looks like this:
    "1|11|25|1|1|0000000001|0|0|Y|Main||9|10|A|2002020N01903020M01804020L01706020J01607020I01508020H0140 9020G0130A020F0120B020E0110C020D0100D020C090E020B080F020A070G0209060H0208050I0207040K0205030L0204020 M0203010N02020|9|B|2002030N01903030M01804030L01706030J01607030I01508030H01409030G0130A030F0120B030E0 110C030D0100D030C090E030B080F030A070G0309060H0308050I0307040K0305030L0304020M03030|8|C|2101040O02002 040N01903040M01804040L01706040J01607040I01508040H01409040G0130A040F0120B040E0110C040D0100D040C090E04 0B080F040A070G0409060H0408050I0407040K0405030L0404020M0403010N04020|7|D|2101050O02002050N01903050M01 804050L01706050J01607050I01508050H01409050G0130A050F0120B050E0110C050D0100D050C090E050B080F050A070G0 509060H0508050I0507040K0505030L0504020M0503010N05020|6|E|2101060O02002060N01903060M01804060L01706060 J01607060I01508060H01409060G0130A060F0120B060E0110C060D0100D060C090E060B080F060A070G0609060H0608050I 0607040K0605030L0604020M0603010N06020|5|F|2101070O02002070N01903070M01804070L01706070J01607070I01508 070H01409070G0130A070F0120B070E0110C070D0100D070C090E070B080F070A070G0709060H0708050I0707040K0705030 L0704020M0703010N07020|4|G|2101080O02002080N01903080M01804080L01706080J01607080I01508080H01409080G01 30A080F0120B080E0110C080D0100D080C090E080B080F080A070G0809060H0808050I0807040K0805030L0804020M080301 0N08020|3|H|2101090O02002090N01903090M01804090L01706090J01607090I01508090H11409090G1130A090F5120B090 E5110C090D0100D090C090E090B080F090A070G0909060H0908050I0907040K0905130L0904120M0903110N09021|2|J|210 10A0O020020A0N019030A0M018040A0L016070A0I115080A0H114090A0G1130A0A0F1120B0A0E0110C0A0D0100D0A0C090E0 A0B080F0A0A070G0A09060H0A08040K0A05030L0A04020M0A03010N0A020"

    You will see that after Main||9|10|A|. So Starting, let's take a little sample after |A| . "2002020N01903020M01804020L01706020J0" .Analyzing this we get:
    2chars for the seat number(20),2char for the seat allocationNum(02), 2char + 2char for the XY position( 02 + 0N) + 1 char for status (0).
    So the first bunch would be "2002020N0", the second "1903020M0" etc. There was an older version that did not include the seat and had 7 chars so i divided by 7 to get the total seats of the row. Now i supposedly will divide by 9 as we have 9 chars per session. Now starts the trouble. If you look after the 10 seat the problem is that the 9th seat is not represented by 09 but with 9, hence I character. Are you starting to see the stupidity of the situation? "90E020B080F020A0" It gets 8 characters!!! So everything is messed up. If i try to get the seat number I will get 90 and 80 instead of what they supposed to do (09,08) so I can get 08 and 09, also since there is characters missing the division will fail badly.
    What I want to do, if possible is insert the missing data. So 9 will be 09, to will be 08 etc. The problem is that it's not unique, meaning 9 -09 appears everywhere in the string, and this is not a default string. It may start with 8 seats so it won't be , first seat 20 2nd seat 19 etc.
    I literal don't have a clue on what I can do. How can i "sneak" the zeros in from of the single characters so I can make the string correct?
    Any help would be appreciated.
    This is a .net 2.0 framework
    Slow as hell.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,703

    Re: Very difficult string manipulate due to company stupidity

    I would just process the string serially, as a stream.
    That way you can find the subgroups based on the pattern you're looking for at that point in the stream, determining if it is a single digit at the front based on how many characters you gather when you detect the end of the pattern.
    If you really want to modify the string to insert the characters, then build up an output string inserting the 0's when needed.
    Looping through the string serially and checking the characters and extracting the groups would be the easiest approach in my opinion, rather than trying some global pattern matching.

  3. #3

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,611

    Re: Very difficult string manipulate due to company stupidity

    Hi.
    can't quite figure how to predict the 8 to 9 chars.I am not sure.
    This is what I am trying:
    (Sorry, started with C# testing):

    Code:
     originalRowSubStr = seatsData;
    
                SeatGridRowId = Convert.ToInt32(seatgridrowid);
                RowPhysId = rowphysId;
    // this goes our wrong as the length has been altered due to less characters used than expected (when seats go below number 10)
                int seatsnum = seatsData.Length / 9; /// 8;
    // for now i just put a +1 to have the correct loop but this is a hack, will not work with more or less length, I just luckily matched here
                seatsnum += 1;                                  
                //int seatsnum = seatsData.Length / 7; /// 8;
                String[] seatdata = new String[seatsnum];
                seats = new Seat[seatsnum];
    
    
    //seatdata being on row of data that is determined elsewhere( that is correct so I do not put it here)
      maxX = 0;
                for (int i = 0; i < seatsnum; i++){
                    //used for mapping screen details with Vista data
                    seats[i] = new Seat(seatsData.Substring(i * 9, 9), i + 1, RowPhysId, seatsnum); 
               //     new Seat(seatsData.Substring(i * 8, 8), i+1, RowPhysId, seatsnum);
                 //    String sd = seatsData.Substring(i * 8, 8);
                    String sd = seatsData.Substring(i * 9, 9);
    
                    if (maxX < seats[i].Xposition) {
                        maxX = seats[i].Xposition;                
                    }
                }
    //seat function
    Code:
     public Seat(String data, int rowindex, String rowname, int seatsNumInRow) {
                
                originalSeatData = data;
                
                rowIndex = rowindex;
                rowName = rowname;
    
    //everyting start to mess up when the 2char becomes 1 char...
           //     VistaGridSeat = data.Substring(0, 2);
             //   VistaYpos = data.Substring(2, 2);
               // VistaXpos = data.Substring(4, 2);
                VistaGridSeat = data.Substring(2, 2);
                   VistaYpos = data.Substring(4, 2);
                 VistaXpos = data.Substring(6, 2);
                 string vt = data.Substring(0, 2);
                for (int i = 0; i < VistaCoords.Length; i++) {
    //vistacords = a board with charr2 length that match // can provide if needed but is not the crucial think here
                    if (VistaYpos == VistaCoords[i]) {
                        Ypos = i;
                        break;
                    }
                }
                
    
                for (int i = 0; i < VistaCoords.Length; i++)
                {
                    if (VistaXpos == VistaCoords[i])
                    {
                        Xpos = i;
                        break;
                    }
                }
    
                for (int i = 0; i < VistaCoords.Length; i++)
                {
                    if (VistaGridSeat == VistaCoords[i])
                    {
                        GridSeatNum = i;
                        break;
                    }
                }
                seatLabel = Convert.ToString(seatsNumInRow - (GridSeatNum - 1) + Xpos);
                //Console.WriteLine("Seat label:" + rowName + seatLabel + "  [ (" + seatsNumInRow +"-("+GridSeatNum+"-1)+"+Xpos+") ]");
    
                //Ypos = (VistaCoords.LastIndexOf("|" + VistaYpos + "|"));
                //Xpos = (VistaCoords.LastIndexOf("|"+VistaXpos+"|"));
    
                //Console.WriteLine(data +"=>"+Ypos + "-" +Xpos);
    
                //Ypos = Convert.ToInt32(data.Substring(2, 2));
                //Xpos = Convert.ToInt32(data.Substring(4, 2));
                status = Convert.ToInt32(data.Substring(6, 1));
                //priority = Convert.ToInt32(data.Substring(7, 1));
            }
    Last edited by sapator; Apr 30th, 2015 at 09:45 AM.
    Slow as hell.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: Very difficult string manipulate due to company stupidity

    That is terrible data management, I feel sorry for you!

    I was curious about this, so I decided to tackle it. Here is a console application example and I also made it .NET 2.0 compliant:
    Code:
    Imports System
    
    Public Module Module1
    	Public Sub Main()
    		Dim input As String = "2002020N01903020M01804020L01706020J01607020I01508020H01409020G0130A020F0120B020E0110C020D0100D020C090E020B080F020A070G0209060H0208050I0207040K0205030L0204020M0203010N02020"
    		Dim data() As Seat = {}
    		
    		For x As Integer = 0 To input.Length - 1 Step 9
    			Dim currentInput As String = input.SubString(x, 9)
    			Console.WriteLine("Data: " & currentInput)
    			If currentInput.Substring(0, 1) = "9" Then
    			input = input.Insert(x - 1, "0")
    				currentInput = input.SubString(x, 9)
    				Console.WriteLine("Updated Data: " & currentInput)
    			End If
    
    			Dim currentSeat As Seat = New Seat()
    			With currentSeat
    				.SeatNumber = currentInput.SubString(0, 2) : Console.WriteLine("Seat No: " & .SeatNumber)
    				.AllocationNumber = currentInput.SubString(2, 2) : Console.WriteLine("Allocation No: " & .AllocationNumber)
    				.Position = New Position(currentInput.SubString(4, 2), currentInput.SubString(6, 2)) : Console.WriteLine("Position: " & .Position.ToString)
    				.Status = currentInput.SubString(8) : Console.WriteLine("Status: " & .Status)
    			End With
    
    			ReDim Preserve data(data.Length)
    			data(data.Length - 1) = currentSeat
    			Console.WriteLine()
    		Next
    	End Sub
    End Module
    
    Public Class Seat
    	
    Private _no As String
    	Public Property SeatNumber As String
    		Get
    			Return _no
    		End Get
    		Set(ByVal value As String)
    			If _no <> value Then
    				_no = value
    			End If
    		End Set
    	End Property
    	
    	Private _allocation As String
    	Public Property AllocationNumber As String
    		Get
    			Return _allocation
    		End Get
    		Set(ByVal value As String)
    			If _allocation <> value Then
    				_allocation = value
    			End If
    		End Set
    	End Property
    	
    	Private _position As Position
    	Public Property Position As Position
    		Get
    			Return _position
    		End Get
    		Set(ByVal value As Position)
    			_position = value
    		End Set
    	End Property
    	
    	Private _status As String
    	Public Property Status As String
    		Get
    			Return _status
    		End Get
    		Set(ByVal value As String)
    			If _status <> value Then
    				_status = value
    			End If
    		End Set
    	End Property
    	
    End Class
    
    Public Class Position
    
    	Private _x As String
    	Public Property X As String
    		Get
    			Return _x
    		End Get
    		Set(ByVal value As String)
    			If _x <> value Then
    				_x = value
    			End If
    		End Set
    	End Property
    
    	Private _y As String
    	Public Property Y As String
    		Get
    			Return _y
    		End Get
    		Set(ByVal value As String)
    			If _y <> value Then
    				_y = value
    			End If
    		End Set
    	End Property
    
    	Sub New(ByVal x As String, ByVal y As String)
    		_x = x
    		_y = y
    	End Sub
    
    	Public Overrides Function ToString() As String
    	    Return String.Format("{0}, {1}", _x, _y)
    	End Function
    
    End Class

  5. #5

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,611

    Re: Very difficult string manipulate due to company stupidity

    Thank you for the comforting words.
    I'm anxious to try this but since we have a 3 days Holiday,m going for a small first vacation, I won't be at the office till Monday to give it multiple goes.
    Thank you so much , will post again. Unfortunately I cannot rep you!
    P.S. Can quite figure out how you decide to insert 9 here "If currentInput.Substring(0, 1) = "9" Then" because the data will not always start with 19, it can start with 18 or 17 or 10 or 9 or 3...
    Or course I have to debug because I am terrible at string manips and I probably missing something.
    Slow as hell.

  6. #6
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Very difficult string manipulate due to company stupidity

    Quote Originally Posted by sapator View Post
    You will see that after Main||9|10|A|. So Starting, let's take a little sample after |A| . "2002020N01903020M01804020L01706020J0" .Analyzing this we get:
    2chars for the seat number(20),2char for the seat allocationNum(02), 2char + 2char for the XY position( 02 + 0N) + 1 char for status (0).
    I have two questions.

    1. Is the 'seat number' the only digit sequence that could be 1 or 2 digits?
    2. Is the sequence '2char + 2char for the XY position( 02 + 0N)' always ###L (where #= digit, L = letter)?

    If the answer is 'Yes' to both, then why not detect the pattern '#####L#' and work backwards from there to determine if 'seat number' is only 1 digit?

  7. #7
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,329

    Re: Very difficult string manipulate due to company stupidity

    so are you working with strings or integers?

  8. #8
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,703

    Re: Very difficult string manipulate due to company stupidity

    My thought was to process it serially as a stream, as it seems easy to step through the code and observe what it is doing and make adjustments.
    Others with better string manipulation or regex experience might come up with something slicker, but I think just working down through the stream is easier for me.
    You have to account for those "|" sections as well.
    Here is my take on it. I print out the seat portions using Debug.Print to show what it is essentially doing to the seat sequences.
    It does essentially what you asked. Modifying the input string by creating an output string with the inserted 0's where needed.
    Code:
    Public Class Form1
    
      Private ModifiedSeatString As String    'Leading 0's will be added to make all seat data sequences 9 characters in this string
    
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim SampleInput As String = "1|11|25|1|1|0000000001|0|0|Y|Main||9|10|A|2002020N01903020M01804020L01706020J01607020I01508020H01409020G0130A020F0120B020E0110C020D0100D020C090E020B080F020A070G0209060H0208050I0207040K0205030L0204020M0203010N02020|9|B|2002030N01903030M01804030L01706030J01607030I01508030H01409030G0130A030F0120B030E0110C030D0100D030C090E030B080F030A070G0309060H0308050I0307040K0305030L0304020M03030|8|C|2101040O02002040N01903040M01804040L01706040J01607040I01508040H01409040G0130A040F0120B040E0110C040D0100D040C090E040B080F040A070G0409060H0408050I0407040K0405030L0404020M0403010N04020|7|D|2101050O02002050N01903050M01804050L01706050J01607050I01508050H01409050G0130A050F0120B050E0110C050D0100D050C090E050B080F050A070G0509060H0508050I0507040K0505030L0504020M0503010N05020|6|E|2101060O02002060N01903060M01804060L01706060J01607060I01508060H01409060G0130A060F0120B060E0110C060D0100D060C090E060B080F060A070G0609060H0608050I0607040K0605030L0604020M0603010N06020|5|F|2101070O02002070N01903070M01804070L01706070J01607070I01508070H01409070G0130A070F0120B070E0110C070D0100D070C090E070B080F070A070G0709060H0708050I0707040K0705030L0704020M0703010N07020|4|G|2101080O02002080N01903080M01804080L01706080J01607080I01508080H01409080G0130A080F0120B080E0110C080D0100D080C090E080B080F080A070G0809060H0808050I0807040K0805030L0804020M0803010N08020|3|H|2101090O02002090N01903090M01804090L01706090J01607090I01508090H11409090G1130A090F5120B090E5110C090D0100D090C090E090B080F090A070G0909060H0908050I0907040K0905130L0904120M0903110N09021|2|J|21010A0O020020A0N019030A0M018040A0L016070A0I115080A0H114090A0G1130A0A0F1120B0A0E0110C0A0D0100D0A0C090E0A0B080F0A0A070G0A09060H0A08040K0A05030L0A04020M0A03010N0A020"
    
        Dim sb As New System.Text.StringBuilder
        Dim strt As Integer
        Dim ptr As Integer = SampleInput.IndexOf("||") + 2   'A double || apparently begins our seat sequences
        '                                                     there should be three "|" identifying something periodically so skip the first one here
        ptr = SampleInput.IndexOf("|", ptr) + 1
        ptr = SampleInput.IndexOf("|", ptr) + 1
        ptr = SampleInput.IndexOf("|", ptr) + 1
    
        strt = 0
        sb.Append(SampleInput.Substring(strt, ptr - strt)) 'Write the first portion of string skipped so far to the output stringbuilder
        strt = ptr                                         'Set Start pointer to begining of where we're starting to parse next
    
        Do While ptr < SampleInput.Length                  'Work are way through the whole input string
          If SampleInput(ptr) = "|" Then                   'If we found a "|", there should be three of these identifying something so find the next two
            ptr = SampleInput.IndexOf("|", ptr + 1) + 1
            ptr = SampleInput.IndexOf("|", ptr) + 1
            sb.Append(SampleInput.Substring(strt, ptr - strt))  'and append that sequence to the output
            strt = ptr
    
          Else 'Must be a seat sequence
            'The 8th character in the seat seqence should be a letter if we have 9 characters for the seat, if it is a number, then we must have 8 characters
    
            ptr += 7 'skip down to the 8th character
    
            If Char.IsDigit(SampleInput(ptr)) Then             'a digit indicates 8 character seat item, so we need to add a prefix 0 to the 8 character string to make it 9 characters
              sb.Append("0")                                   'output a leading 0 to the beginning of the sequnce (by appending it to the output before the rest of the sequence)
              ptr = ptr + 1                                                'Point to the beginning of the next sequence
              sb.Append(SampleInput.Substring(strt, ptr - strt))
              Debug.Print("0{0}", SampleInput.Substring(strt, ptr - strt)) 'to show what were doing
              strt = ptr
    
            Else                                                          'it is a letter, which we expect for 9 character seat identifier
              ptr = ptr + 2                                               'point to the beginning of the next sequence (skip over the status character)
              sb.Append(SampleInput.Substring(strt, ptr - strt))
              Debug.Print("{0}", SampleInput.Substring(strt, ptr - strt)) 'to show what were doing
              strt = ptr
            End If
    
          End If
        Loop
        ModifiedSeatString = sb.ToString
    
      End Sub
    End Class
    The debug.print output in the Output window looks like
    Code:
    2002020N0
    1903020M0
    1804020L0
    1706020J0
    1607020I0
    1508020H0
    1409020G0
    130A020F0
    120B020E0
    110C020D0
    100D020C0
    090E020B0
    080F020A0
    070G02090
    060H02080
    050I02070
    040K02050
    030L02040
    020M02030
    010N02020
    2002030N0
    1903030M0
    1804030L0
    1706030J0
    1607030I0
    1508030H0
    1409030G0
    130A030F0
    120B030E0
    110C030D0
    100D030C0
    090E030B0
    080F030A0
    070G03090
    060H03080
    050I03070
    040K03050
    030L03040
    020M03030
    2101040O0
    2002040N0
    1903040M0
    1804040L0
    1706040J0
    1607040I0
    1508040H0
    1409040G0
    130A040F0
    120B040E0
    110C040D0
    100D040C0
    090E040B0
    080F040A0
    070G04090
    060H04080
    050I04070
    040K04050
    030L04040
    020M04030
    010N04020
    2101050O0
    2002050N0
    1903050M0
    1804050L0
    1706050J0
    1607050I0
    1508050H0
    1409050G0
    130A050F0
    120B050E0
    110C050D0
    100D050C0
    090E050B0
    080F050A0
    070G05090
    060H05080
    050I05070
    040K05050
    030L05040
    020M05030
    010N05020
    2101060O0
    2002060N0
    1903060M0
    1804060L0
    1706060J0
    1607060I0
    1508060H0
    1409060G0
    130A060F0
    120B060E0
    110C060D0
    100D060C0
    090E060B0
    080F060A0
    070G06090
    060H06080
    050I06070
    040K06050
    030L06040
    020M06030
    010N06020
    2101070O0
    2002070N0
    1903070M0
    1804070L0
    1706070J0
    1607070I0
    1508070H0
    1409070G0
    130A070F0
    120B070E0
    110C070D0
    100D070C0
    090E070B0
    080F070A0
    070G07090
    060H07080
    050I07070
    040K07050
    030L07040
    020M07030
    010N07020
    2101080O0
    2002080N0
    1903080M0
    1804080L0
    1706080J0
    1607080I0
    1508080H0
    1409080G0
    130A080F0
    120B080E0
    110C080D0
    100D080C0
    090E080B0
    080F080A0
    070G08090
    060H08080
    050I08070
    040K08050
    030L08040
    020M08030
    010N08020
    2101090O0
    2002090N0
    1903090M0
    1804090L0
    1706090J0
    1607090I0
    1508090H1
    1409090G1
    130A090F5
    120B090E5
    110C090D0
    100D090C0
    090E090B0
    080F090A0
    070G09090
    060H09080
    050I09070
    040K09051
    030L09041
    020M09031
    010N09021
    21010A0O0
    20020A0N0
    19030A0M0
    18040A0L0
    16070A0I1
    15080A0H1
    14090A0G1
    130A0A0F1
    120B0A0E0
    110C0A0D0
    100D0A0C0
    090E0A0B0
    080F0A0A0
    070G0A090
    060H0A080
    040K0A050
    030L0A040
    020M0A030
    010N0A020
    p.s. Looking at the list, I see I was wrong. The eight character is not always a Letter, but it looks like it "worked" anyway. I'll have to check to see why it appears to have worked given that false assumption would seem like it should have failed.

    p.p.s It looks like I was just lucky. The letters started high enough that the seats always reached single digits on the front of the sequence before the 8th character ceased being a letter, so there are no cases where a 9 character sequence has a digit for the 8th character.

    p.p.p.s I didn't check to see if the code written was compliant with .Net 2.0. Just a minute.... started a new project (vb2010) targeting 2.0 framework....pasted code in, added a button... Yeah, still works fine. Just mind the Column 8 Lettering flaw the code is based on. If the rows are always going to decrement over a set, you can probably just check for the next number you expect to see if it is one digit or two. If you just processed 10, so are expecting 9 and you get 90, then you know you have to make an adjustment.
    Last edited by passel; Apr 30th, 2015 at 09:41 PM.

  9. #9

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,611

    Re: Very difficult string manipulate due to company stupidity

    @TnTinMN 1) I am not sure as I found out this issue 2 days ago so I am guessing they might have other goof ups 2)Don't think so as this passes through an array of validate values that , as I see they can be other non Letter numbers.

    @ident strings only.

    @ passel Thanks for the code. So there is a flaw if the seats starts from lower place? Don't have a PC with VS here to check everything, should contact test on every seat diagram we have available at work to see who it's working. We have a god class seat diagram that the row has only 6 seats. I'm guessing if there is an error there would be there. Also the front seats in a diagram might be less than 10, so again I will check there also.
    Will get back.Thanks.
    Slow as hell.

  10. #10

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    5,611

    Re: Very difficult string manipulate due to company stupidity

    Following passel's code right now. Not getting any issues ( ). Well apart from a nice bug I found in the seat data string. They actually used a " ' " character in a seat that made it have 10chars instead of nine! That is a clear bug and it is the reason I wanted to attack them for this data manipulation! Digging up the axe of war and let the war software dogs loose. You are going to pay brother!
    Will continue testing on every available seat data combination so i can be 100% sure I'm ok and I do not find any bugs.
    Slow as hell.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width