How can I shorten the strings?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: How can I shorten the strings?

  1. #1
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    66

    How can I shorten the strings?

    I have a serial of strings that each one of them is different from each another.But each one has a length of 49 characters.
    I want to shorten them to about 10-20 characters.And each one of them after shortened should be different from each another too.
    But I don't know how to do it.Can anyone help me with it?
    Thanks a lot.

    or

    Maybe what I really want is to automatically generate a serial of strings with about 10-20 characters that each one of them is different from each another.But I can do that either.I got them with 49 characters.
    Stone

  2. #2
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    66
    no one can help me?
    Stone

  3. #3
    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    762
    What?

    You have a string that contains 49 characters and you just want to "shorten" it to a range of 10 to 20 characters? Um... why? You kind of need to make an algorithm to shorten them a certain way that you need them to be shortened and you have specified at all how you want it done.

    Do you want the last 29-39 characters lopped off? Do you want the characters to be combined into some sort of compression (which probably won't save any string space unless you got strings like "AAAAAAAAAAAAAAABAAAAAA")? Do you want to seperate them?

    You need to be alot more descriptive on what you want/need.

  4. #4
    Join Date
    Feb 2004
    Location
    I am a Malaysian
    Posts
    14

    Re: How can I shorten the strings?

    Originally posted by stoneyrh
    I have a serial of strings that each one of them is different from each another.But each one has a length of 49 characters.
    I want to shorten them to about 10-20 characters.And each one of them after shortened should be different from each another too.
    But I don't know how to do it.Can anyone help me with it?
    Thanks a lot.

    or

    Maybe what I really want is to automatically generate a serial of strings with about 10-20 characters that each one of them is different from each another.But I can do that either.I got them with 49 characters.
    Well, Stoneyrh, your question is really very interesting, I would like to know a little more about it, I will try my best to chime in with any ideas I have, can you explain a little bit clearer ? Can you give an example as to describe what you said ?
    Thanks,

  5. #5
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    66
    I am so sorry for my poor expression.
    The question should be,
    I combine a CpuID-string and the current date-time string as a long string to identify one special user in my database.But the CpuID-string has 32 characters and the current date-time string has 15 characters.So the result string has 47 characters.
    It is too long for my application,because I hope the string can be used as a barcode,and the barcode will be printed to a card which is kept by the user.The long barcode is too long to be read by the barcode-reader.So I want to shorten the string.

    One example of the string is:
    3febf9ff00000f0a007a704000000000200402071122367

    Thanks a lot.
    Stone

  6. #6
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815
    Originally posted by stoneyrh
    One example of the string is:
    3febf9ff00000f0a007a704000000000200402071122367
    You should use a different encoding for your string. From the example string you supplied, you seem to be limiting the string's alphabet to hex characters (0..F). That means that to encode 8 bits of information, you're actually using 16 bits of data (two hex characters), which doubles the effective size of your string. Which type of barcode are you using? The range of available characters will determine how far you can compress the data without loss of information.

  7. #7
    Join Date
    May 2002
    Location
    Germany
    Posts
    487
    As the year changes quite seldom, it might be redundant for your appl. .

    You find several "0" in your string. You should find out whether there is any chance to have numbers in thier place. If there is no chance, you can delete them.

    Is it possible to delete or reduce the timestamp? Are seconds really needed?

    The time and date is internally representated as a number. Maybe you can use this number instead of its string-representation?


    Your question is not providing too much about the context. What is the time-range you have to cover? How acceptable would it be to have the same ID twice from time to time?
    Taking these questions into account, you might i. e. only use the last/first three chars from the CPU-Id. The same you could do with the timestring. If you have not too much traffic, you might be able to use only the day, hours and seconds, or whatever fits best.

    Just by those context-analysis you will find many reduction posibilities.

    In my app. I just use an random int to check the communication partner. So one of 65535 connection-tries is false positive. We can live with that.

    just a few thoughts to think about...


    Marc

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    11,987
    Do you really need to store the machine ID? Are you comparing what is on the barcode with the machine running an app? If so, perhaps you could just use a much smaller check sum instead of the entire ID.

  9. #9
    Join Date
    Sep 2001
    Location
    Victoria, BC, Canada
    Posts
    363
    Sounds like a copy protection scheme to me actually, that's probably why he wants that kind of info.

  10. #10
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    66
    Thanks for all replies above.
    I don't really need to store the machine ID and the millionare second string.I do it because I don't have another method to generate a string at any time on one computer or a different computer that they are different from each other.But now Marc from D give me a very important information that this method can not work either.
    Maybe I should tell you the context of my application.That is:
    This application is somewhat like the application which is used in supermarket to manage the goods.But what my application manage is the user.Anyone who wants to paricipate the fire trainning should enroll his or her information to related branch. The application should record the information and then print a card, which I call User-ID-Card, on which there is a barcode to identify this exactly card and the user. Before the user participate one fire trainning item, he or she should show the card and the application read the barcode by barcode-reader and record that the user has participated this specific fire trainning item yet.
    In the application, I use a database to save all the information the application needs.
    The main problem is that the boss tell me the application should work on a book computer(is it? or mobile computer) which is not connected to the LAN, which SQL Server is running on. So there should be a SQL Server on book computer too.
    Because the user can enroll at the SQL Server on the book computer or on the LAN's Server, I need to combine these two databases(or more than two) into one but not loss any information.So the question to me now is that how I can generate the barcodes generated at one computer at one time differs from the barcodes generated at anoter computer at one time.
    That is the question. The method I used may not work, because just as Marc from D said, the user can change the time on the computer.So I don't know how to do now.I think GUID should be appropriate to this application.But I don't know how to generate it in my application.
    Thanks for your attention.
    Stone

  11. #11
    Join Date
    May 2002
    Location
    Germany
    Posts
    487
    It depends on your opinion about security.
    You might even go for copy-protection and hardware-dongels. But as you talk about trainings I'm not expecting major attempts to cheat your application.

    What about the following: At installation time of your software each system receives a number, just 1, 2, 3,... You will have to type it manually.
    This number becomes a part of the users ID.
    The next part is just a counter, again 1, 2, 3,...
    storing both values in 32-bit unsigned int would give you the ability to use 65000 pcs and each one with 65000 users.

    The actual counter values are stored in the database also.

    With only 4 bytes you would be able to handle your task. If the number of trainees is not big enough, just add a second int-32 to this number.

    You see, I'm talking about something of a minimal solution.

    Even smaller: just allow only number-ranges to be given at each pc. So pc1 may only use 1...1000, pc2 is limited to 1001-2000,....
    So even 2 bytes would do the job. If you do not want to have the initial setting of your application-number/pc-number, you have to find additional unique values.

    But as you are talking about an application that will have to link all input-data, you could cover this problem at the linking-time: when a database merges with the main database, it is still early enough to set additional flags.
    In this case any cross-pc-uniqueness is not needed.


    Marc

  12. #12
    Join Date
    May 2002
    Location
    Germany
    Posts
    487
    just sent the third time.... damned hanging of the internet connection...
    Last edited by Marc from D; March 4th, 2004 at 02:09 AM.

  13. #13
    Join Date
    May 2002
    Location
    Germany
    Posts
    487
    just sent twice...

  14. #14
    Join Date
    Mar 2003
    Location
    Chongqing,China
    Posts
    66
    That is a good idea to solve the problem.
    But there still has some difficulties.
    The manager who installs the application may forget which number has been assigned.So he/she doesn't know what number he/she should give to the computer.
    Stone

  15. #15
    Join Date
    May 2002
    Location
    Germany
    Posts
    487
    OK, you must decide how comfortable your appl. shall be.

    You can write a list manually, so your programming job is easy and the list might get lost in space. But it might be already OK, if your given number is the last three digits of the responsible persons phone number / postal code / room number / ...? This would make it easy to remember.

    You can also do something like the following:

    At installation time each pc gets the number "0". As soon as it tries to merge the local data with the main database, it is asked for the pc-number. Answering "0" it is just given the next free number. At future connections the pc will directly answer with this number. So each new installation of your software will be a new pc for your database and receive a new number.

    This is quite secure and comfortable, but is a little bit work to do.

    I'm not talking at all about the security against intrusions...


    Marc

Page 1 of 2 12 LastLast

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center