Simple String Encryption
HI,
I have been serching around on here for encyption methods but there seems to be soo many i not sure which ones would be good for me.
All i want to do is encypt and decrypt a String record. The encryption doesnt have to be particulary safe but must work for all possible charaters. Basically i am saving records to a text file and i dont want someone to be able to open the text file and read the contents.
I would like to make it as simple as possible so i can just use it like:
String record = "This is the record";
// Encrypted Record
String encRecord = Encryption.encrypt(record);
// Decripted Record
String decRecord = Encryption.decrypt(record);Can anyone stear me in the right direction or give me some sample code i can study.
Thank you in advance
ed
Here is simple encryption routine that I just wrote that I bet would keep someone
stumped for a while.
* This is a simple encryption class that uses simple character substitution.
* To keep the pattern from being obvious the shift factor is a function of the current character's
* position in the source string. This makes sure that all letters aren't encrypted to the same value.
* Usage: To encrypt a string just pass it to the encrypt method.
* String encryptedString = Encryptor.encrypt("Some string.");
* To decrypt a string just pass the encrypted string to the decrypt method.
* String decryptedString = Encryptor.decrypt(encryptedString);
class Encryptor
static final byte [] shiftFactor = {2,5,7,9,13,17,19};
static final int modulo = shiftFactor.length;
static public String encrypt(String s)
char [] ba = s.toCharArray();
for (int i = 0; i < ba.length; i++)
ba[i] += shiftFactor[i%modulo];
return new String(ba);
static public String decrypt(String s)
char [] ba = s.toCharArray();
for (int i = 0; i < ba.length; i++)
ba[i] -= shiftFactor[i%modulo];
return new String(ba);
public static void main(String [] args)
String [] test = {"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz,./<>?;':\"[]{}-=_+!@#$%^&*()`~",
"Now is the time for all good men \n to come to the aid of their country."};
for (int i = 0; i < test.length; i++)
System.out.println(test);
String encrypted = Encryptor.encrypt(test[i]);
System.out.println(encrypted);
System.out.println(Encryptor.decrypt(encrypted) + "\n");
Similar Messages
-
Simple String Compression Functions
Hi all !
I need two simple String compression functions, like
String compress(String what)
and
String decompress(String what)
myString.equals(decompress(compress(myString)))
should result in true.
Primarily I want to encode some plain text Strings so they are not too easy to read, and compression would be a nice feature here.
I already tried the util.zip package, but that one seems to need streams, I simply need Strings.
Any ideas ??
thx
SkippyIt does not do any compression, in fact it does
expansion to better encrypt the string (about 50%).How does that work? You want encryption to
decrease entropy.Why in the world do you say that, pjt33? What a very odd statement indeed. I sure hope you don't work in security, or I do hope you work in security if I'm a bad guy, or a competitor.
Let's say you had a 6-character string you wanted to encrypt.
Well, if you didn't increase the entropy, any 6-character plaintext string would have a 6-character encoded equivalent. And if you decreased entropy (e.g. coding the most commonly used words to shorter strings,) it gets even easier to decrypt.
Presumably there would be no hash collisions, after all, you want this to be reversible.
Hash collisions decrease entropy too, and, by doing so, make it easier to find a plaintext string that happens to hash to a certain value. This is a Bad Thing.
Now, to decode this, the Bad Guy only has to consider the set of 6-character strings and their hash values. You could even precalculate all of the common dictionary words, and everything with common letters and punctuation, making decryption virtually instantaneous. Especially if you had decreased the entropy in the signal, making fewer things I had to try.
But somebody who increased the entropy of their signal by adding random bits and increasing the encrypted size of the message to, say, 64 characters, would make it a lot harder to decrypt.
The ideal encryption system is pure noise; pure randomized entropy. An indecipherable wall of 0 and 1 seemingly generated at random. Statistical methods can't be used against it; nothing can be deciphered from it; it's as decipherable and meaningless as radio hiss. Now that's encryption! -
Hi everyone,
I have a binary String representing a character - for example, character f = 01100110
I also have a cipher String represented as 0's and 1's that could be upto 128 in length = 01011101010111000101000010001001001111101111011 etc etc.
I want to use the cipher to encrypt the character and the reverse.
I have attempted to use BigInteger to XOR both and to decrypt do the reverse except occasionally I get a number format exception because the binary string is too large (I think).
Here is the code:
public String encrypt(String plain, String secret) {
BigInteger bi = new BigInteger(plain);
BigInteger bii = new BigInteger(secret, 2);
BigInteger res = bi.xor(bii);
return res.toString();
public String decrypt(String encrypted, String secret) {
BigInteger bi = new BigInteger(encrypted);
BigInteger bii = new BigInteger(secret, 2);
BigInteger res = bii.xor(bi);
String str = res.toString();
long val = (long) Long.parseLong(str, 2);
Character c = new Character((char) val);
String out = (String) c.toString();
return out;
}Also the encrypt method is obvious as the bigInteger is the same value except for the last few digits.
Is there any way I can encrypt /decrypt so it is not so obvious and no number format errors?
Thanx in advanceAlmost.
First we need to separate between presentation (Strings) and business logic(byte arrays).
1. Convert input from Strings to byte arrays.
1.1 Convert plain text to byte array.
1.2 Convert secret (probably provided as a String containing '0' and '1' only) to byte array
(may require validation that it is only '0' and '1' and the length is multiple of 8 and not
more than 128)
2. Encrypt byte array plain text with byte array secret (see bellow).
3. Convert result to a String of '0' and '1' (or hex, but it seems not to be the case).
Step 2 details:
Suppose your secret is 24 bits (3 bytes).
XOR plain[0] with secret[0]
XOR plain[1] with secret[1]
XOR plain[2] with secret[2]
XOR plain[3] with secret[0]
etc.
(Unless more details have been given about the encryption algorithm - this one is ok, but not
very effective).
Your byte by byte encryption does not make sense. In your case an 'A' will always
encrypt to the same thing and so will a 'B'. It's extremely easy to break it, just by knowing the
frequency of letters in the English language.
Edited by: baftos on Mar 14, 2008 6:18 PM -
Simple string / bytes problem
Hi
I'm basically trying to simulate DES in java from scratch (so no use of existing API's or anything). I've got a basic idea of how DES works (use of a feistel cipher).
So to start off I'm trying to get the bytes of a string with this simple program:
public class Test {
public static void main(String[] args) {
String testString = "hello";
System.out.println(testString.getBytes());
}The output consists of some characters (namely numbers, letters and 1 special character).
But when I change the variable testString to some other String, complie and run I still get the same output even though the String is different. Also why are there 9 characters for a String thats only 5 characters long?
ThanksWhen you use System.out.println( something ) it uses to the toString() method of the object referenced by 'something'. When the something is an array such as an array of bytes the toString() methed returns a pseudo reference to the array which in no way reflects the content of the array.
If you just want to see the content of the array then use Arrays.toString(something) to generate a String representation of the content of the array.
Also, the use of String.getBytes() will convert the String to bytes using your default character encoding. This is rarely what you want since the result may depend on which platform you are working on. In my view, the safest and best approach is to explicitly define the encoding and since it will encode ALL characters one can throw at it I always use utf-8. So, to convert a String to bytes I would usebyte[] bytesOfString = "your string".getBytes("utf-8");and to convert them back to a String I would useString yourString = new String(bytesOfString,"utf-8");One final point, do not assume that an apparently random array of bytes such as one gets from DES encryption can be converted to a String using the above. In general it can't because not all bytes and byte sequences are valid for a particular character encoding. If you absolutely have to have a String representation then you should encode (not encrypt) the bytes using something like Base64 or Hex encoding.
Edited by: sabre150 on Jan 27, 2008 3:04 PM -
Write a simple string to a file.
I have a string that is formatted with new lines that I want to write to a file as is. I have not been able to create a File Partner Link that can successfully write the content.
The opaque approach creates an empty file.
I have tried defining a new schema as a string, a delimited and a fixed length and the closest I have come is getting the last line written with fixed length.
This is the input schema. I want to write the file element. The complex_child element contains values I would use to build the file name.
<xs:complexType name="complex_parent_type">
<xs:sequence>
<xs:element name="complex_child" type="ns1:complex_child_type"/>
<xs:element name="file" type="xs:string"/>
</xs:sequence>
</xs:complexType>
Anybody have any success? I would think this should be a simple process. We would prefer not to use embedded Java.
Thanks,
Wes.Hi Wes,
You could try using this schema:
<?xml version="1.0" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
targetNamespace="..."
xmlns:tns="..."
elementFormDefault="qualified" attributeFormDefault="unqualified"
nxsd:encoding="US-ASCII" nxsd:stream="chars"
nxsd:version="NXSD" >
<xsd:element name="file" type="xsd:string" nxsd:style="terminated"
nxsd:terminatedBy="${eof}">
</xsd:element>
</xsd:schema>
You could copy over the contents of the string that you want to write out into the element above and then use the "invoke" on a file adapter PL to write it out.
Regards,
Narayanan -
Tcpcrypt - Simple, transparent encryption for any TCP application
Long story short, tcpcrypt is a new TCP extension and draft standard for automatic transport-layer encryption. Using it as simple as installing the package and running /etc/rc.d/tcpcryptd start
I created an AUR package here: http://aur.archlinux.org/packages.php?ID=40308
What does it do?
Opportunistic - automatically enabled if both ends support tcpcrypt, gracefully falls back to normal TCP if not
No configuration - Just works
Transparent - any regular TCP application can use it
No kernel compilation necessary - just run a daemon to enable (Eventually it'll be merged into the Linux kernel, but until then this is a VERY convenient solution)
Works on Linux, OSX, FreeBSD and Windows
Low overhead
It was recently covered in an LWN.net article and presented on USENIX Security Symposium. (IETF/RFC draft, Design paper PDF, tcpcrypt.org website)
Basically, it's what IPsec and TLS always should have been. The catch is, it doesn't do any authentication itself, but it makes it very easy for applications to do auhtentication (to prevent MITM etc). But un-authenticated encryption is still much better than no encryption at all.
They also have plans to improve TLS, such that encryption is done by tcpcrypt, with TLS only adding authentication (with PKI certificates as usual). In other words, both http:// and https:// would be encrypted with tcpcrypt, but https:// uses a server SSL certificate.
Testing
Record yourself among the first tcpcrypt users: Hall of Fame
If you install it on 2 machines, try ssh'ing between them and run tcnetstat -- it will show a list of connections
You can also test it by going to tcpcrypt.org; at the bottom it will say something like "Your tcpcrypt session ID is: DAC08BB7DBD2..."
In the worst case, the tcpcryptd daemon may crash and temporarily halt all your TCP connections. When that happens, run /etc/rc.d/tcpcryptd stop and un-encrypted connections will resume as if nothing happened
Please report bugs to their bug tracker: http://github.com/sorbo/tcpcrypt/issues
Last edited by intgr (2010-08-27 15:23:16)The memory leak in tcpcryptd has been fixed, so anyone who was turned off by this bug can start using it again.
faelar wrote:I've waited for the issue to be fixed, but it seems I can't run tcpcryptd currently :
tcpcryptd: nfq_unbind_pf(): Invalid argument
Weird, I built tcpcrypt-git right now (20101011-1) and it's working as expected.
Can you install ltrace, run this command as root and post its output?
ltrace -l /usr/lib/libnetfilter_queue.so.1 -l /usr/lib/libnfnetlink.so.0 tcpcryptd
Thanks!
Last edited by intgr (2010-10-11 20:27:07) -
Hello,
I've been searching online, and on the HP website but can't find much information about simple pass's security. I would like to know if and how my passwords are encrypted. I'm used to using LastPass, and other password managers that are more straight forward about how they secure your data. If anyone can help with more information, I would be very appreciative!
Thanks!
JackAricari, I appreciate the reply. I understand what you are saying. However, as I understood, the software would allow you to input passwords for personal website logins, and then use the figure print reader instead of entering that password each subsequent login. Thus the my passwords are being 'remembered' or kept internally as data in some manner. It is that data, that I wanted to know how it is protected, encrypted, ect. If it is just sitting in a plain file on my computer, or HP's servers that concerns me. Do you know how the file containing those passwords that are then referred to by the figure print reader is kept safe? Or do I miss understand how it works? Surely the websites still needs told my passwords- it doesn't keep record of my figure print. Thanks so much for the help! -Jack
-
Havin probs drawing a simple string
hi 2 all
i've got this simple applet,but it doesn't really what i want!i only see a gry rect!but he has to draw a string!
import java.applet.*;
import java.net.*;
import java.io.*;
import java.awt.*;
public class CCounter1 extends Applet {
Font anzeiger;
public void init() {
anzeiger=new Font("Arial",Font.BOLD,16);
public String readFile(String f) {
try {
String zahl1="";
String aLine = "";
URL source = new URL(getCodeBase(), f);
BufferedReader br =new BufferedReader(new InputStreamReader(source.openStream()));
while(null != (aLine = br.readLine()))
zahl1.concat(zahl1);
br.close();
return aLine;
catch(Exception e) {
e.printStackTrace();
return null;
public void paint(Graphics g){
setBackground(Color.gray);
g.setColor(Color.white);
setFont(anzeiger);
g.fillRect(100,100,100,100);
g.drawString(readFile("besucher.hansi"),10,20);
g.drawString("Hallo",200,200);You set the color to white... fill the area and then paint a string (with the same white color)
first... set a color... fill it... then set another color... draw your string... done
Grtz David -
Hallo,
I need to encrypt password with MD5 algorithm. I'm using following method:
public static byte[] encryptStr(byte[] chars){
MessageDigest digest=null;
try {
digest = MessageDigest.getInstance("MD5");
digest.reset();
digest.update(chars);
return digest.digest();
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(RzJUtils.class.getName()).log(Level.SEVERE, null, ex);
return null;
My application communicates with a servlet, so I have to send encrypted password to serwlet. But if I use the method in sending desktop application I get as encryption result following string: � �o,H�0�3�
�
If I use the same method serverside (in servlet) I get following string: o,Hćş0Đ3
Î
I've tried with convertion between different charsets but without success. Why are the results different? Is there a way to get eqaul results in desktop application and in servlet?
with regards
Rafal ZiolkowskiOf course, what you get isn't a String at all, it's a byte array. If you want to display it I suggest you do so in hex. You can do this easily enough with something like:
private String toHex(byte[] bytes) {
StringBuilder sb = new StringBuilder(bytes.length * 2);
for (byte b : bytes)
sb.append(String.format("%02x" b & 255);
return sb,toString();
}That gets rid of problems w.r.t character encoding (at least, of the digest).
Incidentally it's confusing to call a digest "encryption". -
DB Adapter 902 binding exception while passing parameters for simple string
Hi,
I have an PlSQL API with two input paramters of string type... But this is only started after XML validation TRUE on the BPM server.
The error is
<bindingFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="code"><code>902</code>
</part><part name="detail"><detail>
Internal Exception: java.sql.SQLException: ORA-00902: invalid datatype
Error Code: 902</detail>
</part><part name="summary"><summary>file:/oracle/product/10.1.3/soa/bpel/domains/Website/tmp/.bpel_BPELProcess1_1.0_c64929dfd2dacf95db3c9da081c1797d.tmp/callingAPI.wsdl [ callingAPI_ptt::callingAPI(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'callingAPI' failed due to: Error while trying to prepare and execute an API.
An error occurred while preparing and executing the XXRBA.XXRBA_WEB_ADAPTER.FETCH_CUSTOMERS API. Cause: java.sql.SQLException: ORA-00902: invalid datatype
[Caused by: ORA-00902: invalid datatype
; nested exception is:
ORABPEL-11811
Error while trying to prepare and execute an API.
An error occurred while preparing and executing the XXRBA.XXRBA_WEB_ADAPTER.FETCH_CUSTOMERS API. Cause: java.sql.SQLException: ORA-00902: invalid datatype
[Caused by: ORA-00902: invalid datatype
Check to ensure that the API is defined in the database and that the parameters match the signature of the API. Contact oracle support if error is not fixable.
</summary>
</part></bindingFault>
The input XSD parameters in BPEL input
<element name="input" type="string"/>
The input XSD parameters in ADAPTER
<element name="P_WEB_ACCOUNT" type="string" db:index="1" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
<element name="P_SOLICITED_ONLY" type="string" db:index="2" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
The assignment I am doing in the .bple file is
<assign name="Assign_1">
<copy>
<from expression="bpws:getVariableData('inputVariable','payload','/client:BPELProcess1ProcessRequest/client:input')"/>
<to variable="Invoke_1_callingAPI_InputVariable" part="InputParameters"
query="/ns2:InputParameters/ns2:P_WEB_ACCOUNT"/>
</copy>
<copy>
<from expression="string('o')"/>
<to variable="Invoke_1_callingAPI_InputVariable" part="InputParameters"
query="/ns2:InputParameters/ns2:P_SOLICITED_ONLY"/>
</copy>
</assign>
--KhaleelYou have an attribute type in an object service that is supposed to be numeric, but when reading form the database it seems that is retrieving a non-numeric content...
Cheers,
Vlad -
UTF-8 working in JSP not in JavaBean (when assigned to a simple String)
I am struggling with for last few hours. All I am doing is
public class Text extends Object implements Serializable {
public static Hashtable ht = new Hashtable();
public static void initL10N(){
public static String xyz = "आपके";
ht.put("hindi",xyz);
in a JavaBean and trying to access the string in a Jsp Out.jsp as <%=Text.ht.get("hindi")%> I am getting Junk characters.
But to my surprise: If I do that in a jsp: as (since I declared the ht as public static it's accessable to the new JSP called L10NInit.jsp
<%
Text.ht.put("hindi2","आपके")l
%>
and execute the Out.jsp and then execute my orginal jsp to get the string as <%=Text.ht.get("hindi2")%> it displays beautifully.
I tried every thing else before turning to this forum. Please help.
Environment: NetBeans5.5In the JSP also I am assigining straignt hindi chars (some how forum displayed entities) as वैश्विक
-
Method to Format a string column containing HTML tags as simple string.
Hello,
I am working with formating a string column which holds Html tags.
I want to remove these tags from the actual data which has to be shown on the BI Publisher report.
Can you suggest how can we format this in the DataSet designer of BI publisher so that my data is recognised on the Layout designer.
I have been trying to create an expression using the "Add Element by Expression" option to format this html tag data as normal string without the tags.
Can you suggest if this is the correct method to do this.
I found this below code being used in an existing DateSet but i am not able to recreate a similar formating on this kind of data column.
<![CDATA' || '['|| TO_CLOB(SUCCESS_CRITERIA) || ']' || ']>
Kindly suggest if you have any idea on the above mentioned issue.
Thanks,
ShwetaAnd read this:
Navigate yourself around pitfalls related to the Runtime.exec() method
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html -
Simple string optimization question
ABAPpers,
Here is the problem description:
In a SELECT query loop, I need to build a string by concatenating all the column values for the current row. Each column is represented as a length-value pair. For example, let's say the current values are:
Column1 (type string) : 'abc '
Column2 (type integer) : 7792
Column3 (type string) : 'def '
The resulting string must be of the form:
0003abc000477920003def...
The length is always represented by a four character value, followed by the actual value.
Note that the input columns may be of mixed types - numeric, string, date-time, etc.
Given that data is of mixed type and that the length of each string-type value is not known in advance, can someone suggest a good algorithm to build such a result? Or, is there any built-in function that already does something similar?
Thank you in advance for your help.
PradeepHi,
At the bottom of this message, I have posted a program that I currently wrote. Essentially, as I know the size of each "string" type column, I use a specific function to built the string. For any non-string type column, I assume that the length can never exceed 25 characters. As I fill 255 characters in the output buffer, I have to write the output buffer to screen.
The reason I have so many functions for each string type is that I wanted to optimize concatenate operation. Had I used just one function with the large buffer, then "concatenate" statement takes additional time to fill the remaining part of the buffer with spaces.
As my experience in ABAP programming is limited to just a couple of days, I'd appreciate it if someone can suggest me a better way to deal with my problem.
Thank you in advanced for all your help. Sorry about posting such a large piece of code. I just wanted to show you the complexity that I have created for myself :-(.
Pradeep
REPORT ZMYREPORTTEST no standard page heading line-size 255.
TABLES: GLPCA.
data: GLPCAGL_SIRID like GLPCA-GL_SIRID.
data: GLPCARLDNR like GLPCA-RLDNR.
data: GLPCARRCTY like GLPCA-RRCTY.
data: GLPCARVERS like GLPCA-RVERS.
data: GLPCARYEAR like GLPCA-RYEAR.
data: GLPCAPOPER like GLPCA-POPER.
data: GLPCARBUKRS like GLPCA-RBUKRS.
data: GLPCARPRCTR like GLPCA-RPRCTR.
data: GLPCAKOKRS like GLPCA-KOKRS.
data: GLPCARACCT like GLPCA-RACCT.
data: GLPCAKSL like GLPCA-KSL.
data: GLPCACPUDT like GLPCA-CPUDT.
data: GLPCACPUTM like GLPCA-CPUTM.
data: GLPCAUSNAM like GLPCA-USNAM.
data: GLPCABUDAT like GLPCA-BUDAT.
data: GLPCAREFDOCNR like GLPCA-REFDOCNR.
data: GLPCAAWORG like GLPCA-AWORG.
data: GLPCAKOSTL like GLPCA-KOSTL.
data: GLPCAMATNR like GLPCA-MATNR.
data: GLPCALIFNR like GLPCA-LIFNR.
data: GLPCASGTXT like GLPCA-SGTXT.
data: GLPCAAUFNR like GLPCA-AUFNR.
data: data(255).
data: currentPos type i.
data: lineLen type i value 255.
data len(4).
data startIndex type i.
data charsToBeWritten type i.
data remainingRow type i.
SELECT GL_SIRID
RLDNR
RRCTY
RVERS
RYEAR
POPER
RBUKRS
RPRCTR
KOKRS
RACCT
KSL
CPUDT
CPUTM
USNAM
BUDAT
REFDOCNR
AWORG
KOSTL
MATNR
LIFNR
SGTXT
AUFNR into (GLPCAGL_SIRID,
GLPCARLDNR,
GLPCARRCTY,
GLPCARVERS,
GLPCARYEAR,
GLPCAPOPER,
GLPCARBUKRS,
GLPCARPRCTR,
GLPCAKOKRS,
GLPCARACCT,
GLPCAKSL,
GLPCACPUDT,
GLPCACPUTM,
GLPCAUSNAM,
GLPCABUDAT,
GLPCAREFDOCNR,
GLPCAAWORG,
GLPCAKOSTL,
GLPCAMATNR,
GLPCALIFNR,
GLPCASGTXT,
GLPCAAUFNR) FROM GLPCA
perform BuildFullColumnString18 using GLPCAGL_SIRID.
perform BuildFullColumnString2 using GLPCARLDNR.
perform BuildFullColumnString1 using GLPCARRCTY.
perform BuildFullColumnString3 using GLPCARVERS.
perform BuildFullColumnString4 using GLPCARYEAR.
perform BuildFullColumnString3 using GLPCAPOPER.
perform BuildFullColumnString4 using GLPCARBUKRS.
perform BuildFullColumnString10 using GLPCARPRCTR.
perform BuildFullColumnString4 using GLPCAKOKRS.
perform BuildFullColumnString10 using GLPCARACCT.
perform BuildFullColumnNonString using GLPCAKSL.
perform BuildFullColumnNonString using GLPCACPUDT.
perform BuildFullColumnNonString using GLPCACPUTM.
perform BuildFullColumnString12 using GLPCAUSNAM.
perform BuildFullColumnNonString using GLPCABUDAT.
perform BuildFullColumnString10 using GLPCAREFDOCNR.
perform BuildFullColumnString10 using GLPCAAWORG.
perform BuildFullColumnString10 using GLPCAKOSTL.
perform BuildFullColumnString18 using GLPCAMATNR.
perform BuildFullColumnString10 using GLPCALIFNR.
perform BuildFullColumnString50 using GLPCASGTXT.
perform BuildFullColumnString12 using GLPCAAUFNR.
ENDSELECT.
if currentPos > 0.
move '' to datacurrentPos.
write: / data.
else.
write: / '+'.
endif.
data fullColumn25(29).
data fullColumn1(5).
Form BuildFullColumnString1 using value(currentCol).
len = STRLEN( currentCol ).
concatenate len currentCol into fullColumn1.
data startIndex type i.
data charsToBeWritten type i.
charsToBeWritten = STRLEN( fullColumn1 ).
data remainingRow type i.
do.
remainingRow = lineLen - currentPos.
if remainingRow > charsToBeWritten.
move fullColumn1+startIndex(charsToBeWritten) to
data+currentPos(charsToBeWritten).
currentPos = currentPos + charsToBeWritten.
exit.
endif.
if remainingRow EQ charsToBeWritten.
move fullColumn1+startIndex(charsToBeWritten) to
data+currentPos(charsToBeWritten).
write: / data.
currentPos = 0.
exit.
endif.
move fullColumn1+startIndex(remainingRow) to
data+currentPos(remainingRow).
write: / data.
startIndex = startIndex + remainingRow.
charsToBeWritten = charsToBeWritten - remainingRow.
currentPos = 0.
enddo.
EndForm.
data fullColumn2(6).
Form BuildFullColumnString2 using value(currentCol).
len = STRLEN( currentCol ).
concatenate len currentCol into fullColumn2.
data startIndex type i.
data charsToBeWritten type i.
charsToBeWritten = STRLEN( fullColumn2 ).
data remainingRow type i.
do.
remainingRow = lineLen - currentPos.
if remainingRow > charsToBeWritten.
move fullColumn2+startIndex(charsToBeWritten) to
data+currentPos(charsToBeWritten).
currentPos = currentPos + charsToBeWritten.
exit.
endif.
if remainingRow EQ charsToBeWritten.
move fullColumn2+startIndex(charsToBeWritten) to
data+currentPos(charsToBeWritten).
write: / data.
currentPos = 0.
exit.
endif.
move fullColumn2+startIndex(remainingRow) to
data+currentPos(remainingRow).
write: / data.
startIndex = startIndex + remainingRow.
charsToBeWritten = charsToBeWritten - remainingRow.
currentPos = 0.
enddo.
EndForm.
data fullColumn3(7).
Form BuildFullColumnString3 using value(currentCol).
EndForm.
data fullColumn4(8).
Form BuildFullColumnString4 using value(currentCol).
EndForm.
data fullColumn50(54).
Form BuildFullColumnString50 using value(currentCol).
EndForm.
Form BuildFullColumnNonString using value(currentCol).
move currentCol to fullColumn25.
condense fullColumn25.
len = STRLEN( fullColumn25 ).
concatenate len fullColumn25 into fullColumn25.
data startIndex type i.
data charsToBeWritten type i.
charsToBeWritten = STRLEN( fullColumn25 ).
data remainingRow type i.
do.
remainingRow = lineLen - currentPos.
if remainingRow > charsToBeWritten.
move fullColumn25+startIndex(charsToBeWritten) to
data+currentPos(charsToBeWritten).
currentPos = currentPos + charsToBeWritten.
exit.
endif.
if remainingRow EQ charsToBeWritten.
move fullColumn25+startIndex(charsToBeWritten) to
data+currentPos(charsToBeWritten).
write: / data.
currentPos = 0.
exit.
endif.
move fullColumn25+startIndex(remainingRow) to
data+currentPos(remainingRow).
write: / data.
startIndex = startIndex + remainingRow.
charsToBeWritten = charsToBeWritten - remainingRow.
currentPos = 0.
enddo.
EndForm. -
Hi All:
I am stuck with a small situation, I would appreciate if someone can help me with that. I have 2 strings:
String 1 - "abc"
String 2 - "I want to check if abc is in the middle"
How can I check if the string 1 "abc" is in the middle of the string 2. I mean the String 2 does not start with "abc" and it does not end with "abc", I want to check if it is somewhere between the string.
Thanks,
Kunalint i = s2.indexOf(s1);
if((i > 0) && ((i + s1.length()) < s2.length())) {
// somewhere in the middle
} else if(i == 0) {
// start
} else if((i + s1.length()) == s2.length()) {
// end
} else if(i == -1) {
// nowhere
} -
Simple String replacement problem
I want to replace every string of the type:
"^\\d+,[^,]+,,[^,]*,[^,]*$"
to:
"^\\d+,[^,]+,1,[^,]*,[^,]*$"
So that "1234,something,,something,something" becomes "1234,something,1,something,something"
What's the best way to do this?What are your EXACT requirements?
Do you want to replace all ,, with ,1, ?
Only a ,, that comes after number,something?
Right now, it looks like replaceFirst(",,", ",1,") will work. I doubt that's what you want, but there are probably a whole bunch of different regexes that could turn that input into that output.
Maybe you are looking for
-
Facebook share button in web gallery
Is it possible somehow to add a facebook share button to the photos in the web gallery? I use the web module to create galleries of athletes - and I want to give them the possibilty to share their photo by clicking in the gallery instead of right cli
-
I can't get Battlefield 2 or 2142 to run. It shows the splash screen, goes black for a second and then returns to the desktop. From what I can figure out through Google I need the latest drivers for the integrated Intel 965 Express Chipset. You can d
-
I created a dvd using idvd but did not save the project. Of course, now I have a need to make another copy of that dvd. I have the original dvd. What's the easiest way to make a duplicate. I've tried just ripping the dvd to the desktop using mactheri
-
EWM-ERP movement type integration
Hi, We have EWM 7.0 integrated with ECC 6.0. When I Post Unplanned Goods Issue in EWM with GI process = SCRP (scrapping), I expect to post 551 movement in ECC. However this doesn't happen. On analyzing the inbound queue in ECC 6.0, it is found "reaso
-
i have a bc4j-web-application. i have deployed the jsp-application to the oc4j, running on my windows system. but after opening the jsp page, i got following error: oracle.jbo.JboException: JBO-33001: Cannot find the configuration file mypackage \com