| | |
string translation
![]() |
•
•
Join Date: Jul 2004
Posts: 6
Reputation:
Solved Threads: 0
Hey there,
First off I'm really new to Java so please bear with me. I need to translate a line of text from one form to another. An example line segment has the following format:
" step(sent(1,A,B,vars(Na,Rv,ped(pk(B),cat(N
a,A)))))"
This means that at step 1, A sends to B that which is contained in vars() i.e. Na, Rv and encryption of Na and A (concatenated) using B's public key [ped(pk(B),cat(Na,A))]
The output format I need is the following:
"Knows_B,time_1(Received(B,time_1,(Na,Rv,enc({Na,A},pk_B))))" (ii)
Basically this is the same information that is in the input format but I just need to translate it to the output format above. From what I've read I think i need to use string tokenisers to separate out the input format and thus build up the output form. However I really am at a loss as to how to begin coding this translation. If anyone has the time could they perhaps give me an example of some code that might solve this problem.
If anyone needs more information regarding the input format and how it's related to the output format I will try and elaborate some more on their connection.
Thanks a million.
First off I'm really new to Java so please bear with me. I need to translate a line of text from one form to another. An example line segment has the following format:
" step(sent(1,A,B,vars(Na,Rv,ped(pk(B),cat(N
a,A)))))"
This means that at step 1, A sends to B that which is contained in vars() i.e. Na, Rv and encryption of Na and A (concatenated) using B's public key [ped(pk(B),cat(Na,A))]
The output format I need is the following:
"Knows_B,time_1(Received(B,time_1,(Na,Rv,enc({Na,A},pk_B))))" (ii)
Basically this is the same information that is in the input format but I just need to translate it to the output format above. From what I've read I think i need to use string tokenisers to separate out the input format and thus build up the output form. However I really am at a loss as to how to begin coding this translation. If anyone has the time could they perhaps give me an example of some code that might solve this problem.
If anyone needs more information regarding the input format and how it's related to the output format I will try and elaborate some more on their connection.
Thanks a million.
A string tokenizer will separate that long string in an array of small strings.
I.e.
If you had the string "My@Name@Is@bobby@!" (that's not my name btw
) and you set up a string tokenizer to deliminate by @ you'd end up with an array of 5 elements.
"My","Name","is","bobby","!"
Then you could loop through the array trying to match certain cases.
I'm not sure how the input relates to the output so you can figure that out. But atleast you should know how now. After you tokenize by ")" you'll be left with 8 tokens:
"step"
"sent"
"1,A,B,vars"
"Na,Rv,ped"
"Pk"
"B"
",cat"
"Na,A"
If you want you could deliminate even further by "," but that's up to you.
I.e.
If you had the string "My@Name@Is@bobby@!" (that's not my name btw
) and you set up a string tokenizer to deliminate by @ you'd end up with an array of 5 elements."My","Name","is","bobby","!"
Then you could loop through the array trying to match certain cases.
Java Syntax (Toggle Plain Text)
import java.util.*; public class TokenizerTest{ public static void main(String[] args){ String input = "step(sent(1,A,B,vars(Na,Rv,ped(pk(B),cat(Na,A)))))" String output = null; StringTokenizer st = new StringTokenizer(input,")"); while(st.hasMoreTokens()){ if(st.nextToken().equals("some string")){ // do stuff here } } System.out.println("Output: "+ output); } }
"step"
"sent"
"1,A,B,vars"
"Na,Rv,ped"
"Pk"
"B"
",cat"
"Na,A"
If you want you could deliminate even further by "," but that's up to you.
![]() |
Similar Threads
- Camelcase/Alternating uppwer and lower case letters (C)
- String parsing (C++)
- string problem (converting american english to canadian(british)) (Java)
- initializing a string array in the header (C++)
- StringUtil (Java)
- Read string and use in switch statement (C++)
- Reading in a text file string is not complete (Pascal and Delphi)
Other Threads in the Java Forum
- Previous Thread: java basic
- Next Thread: "String class"
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows





