Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. data formatting

data formatting

Scheduled Pinned Locked Moved Algorithms
questiondatabasesysadmintoolshelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    benjamin yap
    wrote on last edited by
    #1

    Hi, I am developing a website to actually specific an incoming data (in a form of sms) and then validate it. It is like some sms registering service that u see on television. for example they will say something like "SMS < Name>space< NRIC>space< Message> to 7800 and be the first to win attractive prizes!" I actually have a sms server/gateway that will receive the SMS send by the people and the data will be stored in the database Some people might sms < Name>space< Message>space< NRIC> instead of < Name>space< NRIC>space< Message> So, how can i keep a fix format and create an algorithms that will check that the message is in correct format? For now, i have a database table that stores the keyword of each sms. For example, the keyword stored in the database is "Quiz". and people will send an SMS with the text "Quiz NRIC answer" Then i got a script to check the text make sure it tally with the keyword table. But i cant allow it to check whether NRIC come first or the answer come first. Sorry for the long message. But trying to explain as detailed as possible

    N 1 Reply Last reply
    0
    • B benjamin yap

      Hi, I am developing a website to actually specific an incoming data (in a form of sms) and then validate it. It is like some sms registering service that u see on television. for example they will say something like "SMS < Name>space< NRIC>space< Message> to 7800 and be the first to win attractive prizes!" I actually have a sms server/gateway that will receive the SMS send by the people and the data will be stored in the database Some people might sms < Name>space< Message>space< NRIC> instead of < Name>space< NRIC>space< Message> So, how can i keep a fix format and create an algorithms that will check that the message is in correct format? For now, i have a database table that stores the keyword of each sms. For example, the keyword stored in the database is "Quiz". and people will send an SMS with the text "Quiz NRIC answer" Then i got a script to check the text make sure it tally with the keyword table. But i cant allow it to check whether NRIC come first or the answer come first. Sorry for the long message. But trying to explain as detailed as possible

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Assuming NRIC stands for National Registration identity[^]. Do you want to allow users to send SMS in any format or a fixed format? I'd suggest to stick with a specific format something like <Name> space <NRIC> space <Message>. In such case, the following algorithm can be used.

      ProcessMessage(Message)
      Tokens = Split message with space
      name = Token 0
      nric = Token 1
      message = Token 2
      if ValidateName(name) = true and ValidateNric(nric) = true and ValidateMessage(message) = true then
      do processing
      else
      inform user or do other actions
      end

      If you want to have messages in any format, then algorithm like the below will work.

      ProcessMessage(Message)
      Tokens = Split message with space
      for each token in tokens
      if token is name then
      name = token
      else if token is nric then
      nric = token
      else
      message = token
      do processing

      You may need to modify this to handle exceptional situations. :)

      Navaneeth How to use google | Ask smart questions

      B 1 Reply Last reply
      0
      • N N a v a n e e t h

        Assuming NRIC stands for National Registration identity[^]. Do you want to allow users to send SMS in any format or a fixed format? I'd suggest to stick with a specific format something like <Name> space <NRIC> space <Message>. In such case, the following algorithm can be used.

        ProcessMessage(Message)
        Tokens = Split message with space
        name = Token 0
        nric = Token 1
        message = Token 2
        if ValidateName(name) = true and ValidateNric(nric) = true and ValidateMessage(message) = true then
        do processing
        else
        inform user or do other actions
        end

        If you want to have messages in any format, then algorithm like the below will work.

        ProcessMessage(Message)
        Tokens = Split message with space
        for each token in tokens
        if token is name then
        name = token
        else if token is nric then
        nric = token
        else
        message = token
        do processing

        You may need to modify this to handle exceptional situations. :)

        Navaneeth How to use google | Ask smart questions

        B Offline
        B Offline
        benjamin yap
        wrote on last edited by
        #3

        Hi Navaneeth, Really appreciate for your reply :D:D Okay mostly likely i would want the messages to be in any format, because I want to create a generic system that allows the staff in the company to use my system if they need any form of SMS registration from people outside. So i would like my staff to define their own sms format. So which is the best way i can do that? For example, i am from the HR Department and would like to recruit more staff. So i want an SMS services that interested applicants can register. So the HR will define their sms format through my website. <pre>Eg . <RECRUIT>space<NRIC>space<Name>space<PositionInterested> </pre> The staff defined the above format. So any incoming sms will be check against that format. And also another department wants to give away lucky draw prizes thru sms as well, so they define their sms format <pre>eg <LUCKY>space<Name>space<NRIC>space<DateOfBirth></pre> So now there are 2 defined format. So whatever message that comes in will check whether which message it belongs to. Okay so for now, do i store the whole strong of sms format into an sms table? If so, how do i check if which message fits which format? Sorry for another long message

        N 1 Reply Last reply
        0
        • B benjamin yap

          Hi Navaneeth, Really appreciate for your reply :D:D Okay mostly likely i would want the messages to be in any format, because I want to create a generic system that allows the staff in the company to use my system if they need any form of SMS registration from people outside. So i would like my staff to define their own sms format. So which is the best way i can do that? For example, i am from the HR Department and would like to recruit more staff. So i want an SMS services that interested applicants can register. So the HR will define their sms format through my website. <pre>Eg . <RECRUIT>space<NRIC>space<Name>space<PositionInterested> </pre> The staff defined the above format. So any incoming sms will be check against that format. And also another department wants to give away lucky draw prizes thru sms as well, so they define their sms format <pre>eg <LUCKY>space<Name>space<NRIC>space<DateOfBirth></pre> So now there are 2 defined format. So whatever message that comes in will check whether which message it belongs to. Okay so for now, do i store the whole strong of sms format into an sms table? If so, how do i check if which message fits which format? Sorry for another long message

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          benjamin yap wrote:

          So i would like my staff to define their own sms format. So which is the best way i can do that?

          In such cases you may need ask senders to prefix an identifier string with the SMS. So if it is recruitment SMS, format will be **REC** <RECRUIT> space <NRIC> space <Name> space <PositionInterested>. Here, REC is the identifier. You can look at the starting of message and this identifier will help you to determine the type of message. You can have a valid set of identifiers and validate against it. When user defines their own SMS format, you need to build a regular-expression and keep that in the database. Once you identified the message type using the identifier, you can match the remaining text against the pattern and extract contents. :)

          Navaneeth How to use google | Ask smart questions

          B 1 Reply Last reply
          0
          • N N a v a n e e t h

            benjamin yap wrote:

            So i would like my staff to define their own sms format. So which is the best way i can do that?

            In such cases you may need ask senders to prefix an identifier string with the SMS. So if it is recruitment SMS, format will be **REC** <RECRUIT> space <NRIC> space <Name> space <PositionInterested>. Here, REC is the identifier. You can look at the starting of message and this identifier will help you to determine the type of message. You can have a valid set of identifiers and validate against it. When user defines their own SMS format, you need to build a regular-expression and keep that in the database. Once you identified the message type using the identifier, you can match the remaining text against the pattern and extract contents. :)

            Navaneeth How to use google | Ask smart questions

            B Offline
            B Offline
            benjamin yap
            wrote on last edited by
            #5

            Hi Navaneeth, once again thanks for your reply. In such cases you may need ask senders to prefix an identifier string with the SMS. So if it is recruitment SMS, format will be REC space space space . Here, REC is the identifier. You can look at the starting of message and this identifier will help you to determine the type of message. You can have a valid set of identifiers and validate against it. Currently this is what i have. I have a database table called "userapp". Below is the schema and the sample data Userapp userid(int) keyword(varchar(50)) 103 | Temp 132 | Quiz 150 | Lucky For each keyword, i have a seperate for them called app_KEYWORD. So it will be app_Temp, app_Quiz, app_Lucky.

                try {
                    ArrayList array = new ArrayList<String>();
                    String firstword = null;
                    ResultSet rs1 = null;
                    ResultSet rs2 = null;
                    int id = 0;
                    String sql1 = "SELECT \* from userapp";
                    String sql3 = null;
            
                    rs1 = db.SelectDB(sql1);
                    while (rs1.next()) {
                        array.add(rs1.getString("keyword"));
                    }
            
                    for (String i : array) {
                        sql3 = "SELECT \* FROM SMSSERVER\_IN WHERE TEXT LIKE '" + i + "%'";
                        ResultSet rs3 = db.SelectDB(sql3);
                        //out.print(i);
                        while (rs3.next()) {
                            out.print(i);
                            String sql4 = "Insert into app\_" + i + "(originator,text)values(" + rs3.getString("originator") + ",'" + rs3.getString("text") + "')";
                            db.InsertDB(sql4);
                        }
                        String sql5 = "DELETE FROM SMSSERVER\_IN WHERE TEXT LIKE'" + i + "%'";
                        db.DeleteDB(sql5);
                    }
                } catch (Exception ex) {
                }
            

            Above is my code to check the identifier and then store it into the correct database. So instead of storing just 1 keyword, I have to store the whole sms format in it as well? Also, u mention building a regular expression, how can i create an interface that allows the user who define the format to have their own expression? What kind of form or fields should i display in order to build it. Thanks :D

            N 1 Reply Last reply
            0
            • B benjamin yap

              Hi Navaneeth, once again thanks for your reply. In such cases you may need ask senders to prefix an identifier string with the SMS. So if it is recruitment SMS, format will be REC space space space . Here, REC is the identifier. You can look at the starting of message and this identifier will help you to determine the type of message. You can have a valid set of identifiers and validate against it. Currently this is what i have. I have a database table called "userapp". Below is the schema and the sample data Userapp userid(int) keyword(varchar(50)) 103 | Temp 132 | Quiz 150 | Lucky For each keyword, i have a seperate for them called app_KEYWORD. So it will be app_Temp, app_Quiz, app_Lucky.

                  try {
                      ArrayList array = new ArrayList<String>();
                      String firstword = null;
                      ResultSet rs1 = null;
                      ResultSet rs2 = null;
                      int id = 0;
                      String sql1 = "SELECT \* from userapp";
                      String sql3 = null;
              
                      rs1 = db.SelectDB(sql1);
                      while (rs1.next()) {
                          array.add(rs1.getString("keyword"));
                      }
              
                      for (String i : array) {
                          sql3 = "SELECT \* FROM SMSSERVER\_IN WHERE TEXT LIKE '" + i + "%'";
                          ResultSet rs3 = db.SelectDB(sql3);
                          //out.print(i);
                          while (rs3.next()) {
                              out.print(i);
                              String sql4 = "Insert into app\_" + i + "(originator,text)values(" + rs3.getString("originator") + ",'" + rs3.getString("text") + "')";
                              db.InsertDB(sql4);
                          }
                          String sql5 = "DELETE FROM SMSSERVER\_IN WHERE TEXT LIKE'" + i + "%'";
                          db.DeleteDB(sql5);
                      }
                  } catch (Exception ex) {
                  }
              

              Above is my code to check the identifier and then store it into the correct database. So instead of storing just 1 keyword, I have to store the whole sms format in it as well? Also, u mention building a regular expression, how can i create an interface that allows the user who define the format to have their own expression? What kind of form or fields should i display in order to build it. Thanks :D

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              benjamin yap wrote:

              Also, u mention building a regular expression, how can i create an interface that allows the user who define the format to have their own expression? What kind of form or fields should i display in order to build it.

              I'd create a form with one drop-down list, text-box and a button. User will select the available identifiers from the drop-down and enter expected message format in the text-box. You need to define placeholders like <name>, <NRIC> and <message> etc. Assume user entered <name> space <NRIC> space <message>, you need to find the placeholders in this and convert the string into a valid regular expression and keep in database. I am very bad at GUI designs and there may be much better way to design GUI than what I suggested. :)

              Navaneeth How to use google | Ask smart questions

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups