(SOLVED)Perl.... shifting ascii values?
I was curious about Perl today so I started reading a tutorial and before you knew it I had pretty much wrote a small Caeser Cipher program. The only thing I can't figure out is how to shift the ascii characters in the array.
I tried to do it "C" style by adding +1 to the character array index for a +1 shift ("a" +1 = "b"), but apparently Perl doesn't like it, or I didn't use the correct syntax.
Is there any way to do this or am I going to have to use another method? I don't really need to do this program or anything, but trying to get some of the quirks down,
I really like what I have seen so far, really quick to pick up and feels very powerful.
Last edited by Google (2010-12-09 17:38:05)
There's probably a better way (i.e. a method that involves less typing on your part) but you could implement a hash that reads the input string 1 character at a time and outputs the corrected letter, and for any other non shifted input (whitespace and punctuations) just return themselves as values.
example:
my %cypher = (
"a" => "c",
"b" => "d",
"c" => "e",
"y" => "a",
"z" => "b",
" " => " ",
"." => ".");
Last edited by Cyrusm (2010-12-09 17:18:56)
Similar Messages
-
How to find out the ASCII Values for Spanish character
Hi,
I had an requirement to store Spanish character and also need to fileter the records based on the Spanish character.
Kindly guide me for below.
To filter the Records which contains spanish characters?
To get the ASCII Values for the particular column?
E.g. we can find out the ASCII value of 'a' by using the syntax select ASCII('a') from dual.
But I want to find the ASCII Values for the particular column value. Ie. name.
E.g., Client name is "Suresh", I want to the ASCII Values for entire name of "Suresh".
Kindly do the needful help / Guidance on this.
Thanks,
OraharTo expand on what I said in my first post, you want to do something along these lines:
with t (thename) as
select 'Suresh' from dual
select thename
, substr(TheName, level, 1)
, ascii(substr(thename, level))
from t
connect by level <= length(thename);The output of the above query is:
THENAM S ASCII(SUBSTR(THENAME,LEVEL))
Suresh S 83
Suresh u 117
Suresh r 114
Suresh e 101
Suresh s 115
Suresh h 104
6 rows selected.Note that the WITH statement is only there to simulate a table for this example. With a table, all you do is get rid of the with and substitute the name "t" for the name of your table (also the name of the column to whatever name the column has in your table).
Lastly, I suggest you post your question along with, an example table and the output you'd like to get in the PL/SQL forum. There are people there that will give you all kinds of great ways of solving that problem.
HTH,
John. -
How to get the ascii value of characters and numbers
Hi,
Can someone please tell me weater there is an inbuild function in java to get the ascii values....Suppose I want to know the ascii value of a which is 63...then how do i do it...Like if it is c or c++ we can use "toascii" function...
Please help me with an answer...
Thanks
RahulThanks....This solves my problem at present as I have to do validations using ascii values.
regards
rahul -
Problem in converting ASCII value in Dev. and Production
Hi...
The ASCII values for # differ in the development and the production system.
The code below (value 0009 ) populates # in the variable lv_sep.
DATA: lv_sep TYPE x.
FIELD-SYMBOLS : <field> TYPE x.
ASSIGN lv_sep TO <field> CASTING TYPE x.
<field> = 0009.
The the development # = 0009 and in production # = 1000.
Need to know why is this happening.How do you get the XML document? Do you use XSU? You can use:
String str = qry.getXMLString();
to get the result XML document in String.
XSU will escape all of the < and >. Or the the XML document in
one of the column will make the result XML doc not well-formed.
Not quite understand your problem. You can send me your test
case.
i have an application that needs to send an XML document
over the wire. For this reason, I need to convert the
doc into a String at the sending side and back to Doc
at the receiving side. This document is stored in a "CLOB"
column in a table in the database. I use XDK to retrieve
this entire row (including the CLOB - hence this is an XML
document which has a column that itself is an xml document in
string format - this is just the clob read in by XDK).
Thus the row looks like
<ROWSET>
<ROW>
<col1> A <col1>
<CLOB_COL> ..clob value of an xml doc..</CLOB_COL>
</ROW>
</ROWSET>
When I convert this document into String and back, one of the "<"
tags in the clob column document gets changed to "<" and hence
the parsing fails! I have used the latest label of the XDK build
to get the latest parser jar but still i have the same problem.
I am using the following routines for the conversion.
/* for converting document to string */
public static String convertToString(XMLDocument xml) throws
IOException
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
xml.print(pw);
String result = sw.toString();
return result;
/* for converting string to document */
public static XMLDocument convertToXml(String xmlStr)
throws
IOException,SAXException
ByteArrayInputStream inStream = new
ByteArrayInputStream(xmlStr.getBytes());
DOMParser parser = new DOMParser();
parser.setPreserveWhitespace(false);
parser.parse(inStream);
return parser.getDocument(); -
How to find the ascii value in abap
Hi everyone,
i want to get to ascii value of a given character. so wanted to know whether is it possbile to get ascii value of a character in ABAP or not ?
if yes let us know the way to find it ...
thank you.Hi,
Please go through this link below:
http://www.sap-img.com/abap/how-can-i-get-ascii-value-of-any-letter.htm
You can also try using FM's:
CHAR_INT_CONVERSION,
CHAR_HEX_CONVERSION
Hope it helps
Regards
Mansi -
Writing the ASCII value of a character found in a .txt file
I have a program that reads in a file and outputs certain characters to a new smaller file. The program works fine (thanks to some forum help) but I now need to print the ASCII value of the characters that are written to the file.
The problem I'm having (besides writing the ascii value of the char) is that the Unix .txt file has some weird properties. When I run the program on a .txt test file that I created with spaces in it, the program ignores the space characters.
Yet, when I run the program on the Unix file it wites the 'spaces' to the output file. That is why I want to write/print the ASCII value of the "blank "character in the Unix .txt file.
I already serached the forum and did a Google search for Char to ASCII conversion but I didn't find anything.
Thanks,
LS6v
Here's the code and the clips of the ouput files:
package source;
import javax.swing.*;
import java.io.*;
public class Scanner4
public static void main(String[] args)
getContents();
System.exit(0);
public static void getContents()
char charArray[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'0','1','2','3','4','5','6','7','8','9','$','.', '#', '-', '/', '*', '&', '(', ')',' '};
String Chars = null;
String lineSep = System.getProperty("line.separator");
int iterator = 0;
int i = 0;
int charNum = 1;
int lineCount = 1;
// StringBuffer contents = new StringBuffer();
//declared here only to make visible to finally clause
BufferedReader input = null;
BufferedWriter out = null;
try {
//use buffering
//this implementation reads one line at a time
input = new BufferedReader( new FileReader( "C:\\testFile\\test1.txt" ));
out = new BufferedWriter( new FileWriter( "C:\\Scan file test\\Write\\test.txt" ));
String line = null;
out.write( "Character\tLine Number\tCharacter Number" + lineSep );
while (( line = input.readLine()) != null)
//contents.append(System.getProperty("line.separator"));
i = 0;
charNum = 1;
iterator = 0;
while( i < line.length() )
for( int count = 0; count < charArray.length; count++)
if( (charArray[count] != line.charAt(iterator)) && (count+1 == charArray.length) )
out.write( "[" + line.charAt(iterator) + "]\t\t" + "[" + lineCount + "]\t\t" + "[" + charNum + "]" + lineSep);
if( charArray[count] == line.charAt(iterator) )
break;
charNum +=1;
iterator +=1;
i++;
lineCount +=1;
catch (FileNotFoundException ex) {ex.printStackTrace(); System.out.println("File not found.");}
catch (IOException ex){ex.printStackTrace(); System.out.println("IO Error.");}
finally
try{
if (input!= null){
//flush and close both "input" and its underlying FileReader
input.close();
out.close();
catch (IOException ex){ex.printStackTrace(); System.out.println("IO Error #2.");}
My created .txt file:
1. a!asdsad
2. @
3. #
4. $
5. %sdfsdf
6. ^
7. &
8. *
9. (
10. )
11. _
12. +sdfsdfsdf
13. -
14. =
15. ~
16. `
17. dfgdfg;
18. :
19. '
20. "fghfghf
21. ,
22. dfgdfg<
23. .
24. >fghfghfg
25. /
26. gggggggggggggggggggggggg?
27. a
Output for my .txt file:
Character Line Number Character Number
[!] [1] [5]
[@] [2] [4]
[%] [5] [4]
[^] [6] [4]
[_] [11] [5]
[+] [12] [5]
[=] [14] [5]
[~] [15] [5]
[`] [16] [5]
[;] [17] [11]
[:] [18] [5]
['] [19] [5]
["] [20] [5]
[,] [21] [5]
[<] [22] [11]
[>] [24] [5]
[?] [26] [29]************************************************************************
Output generated after reading the .txt file from the unix box:
Character Line Number Character Number
[ ] [1] [17]
[ ] [1] [18]
[ ] [1] [19]
[ ] [1] [6530]
[ ] [2] [2041]
['] [29] [1834]
['] [29] [2023]
['] [30] [1834]
['] [30] [2023]
['] [30] [2066]
['] [47] [2066]
['] [67] [2067]
['] [77] [2066]
[+] [80] [28]Thanks I didn't even think to try and cast it to an int...
The tool I'm using to create my .txt in windows is Notepad.
I wrote a program to simply copy the original (3GB) Unix file and terminated it early so I could see what was there. What I found was some text and symbols and a lot of space between brief bursts of text. I can't really copy and paste an example because the amount of space is too large, it's basically a 3GB unformatted .txt file...
Unix file was created on: unknown
It sounds like the .txt file that I copied from the Unix box was formatted differently. But I thought that the formatting had more to do with end of line issues, not blank space between characters. Because a blank space should be seen by my program and ignored...
Here's the ASCII value of the "blank" spaces:
Character Line Number Character Number
[ ] [1] [17] Ascii Value: [0]
[ ] [1] [18] Ascii Value: [0]
['] [868] [2066] Ascii Value: [39]
[,] [877] [186] Ascii Value: [44]
[,] [877] [276] Ascii Value: [44]
Also, the Ascii value printed for the blank spaces looks like the number zero here but it looks like it has strange points on the bottom of it in my output file. It looks like the extended ASCII character 234 Ω -
I have a pdf file which contains text if i copy all text and paste them into notpad and save file as .txt Is it change the ascii value of text ?
How to know character's encoding is ASCII?
-
Hi,
I have a CFGRID that has 5 columns in which its values are
obtained from the database. There is a single submit button that
would submit to a processor page that updates any records with
changed cells. The problem that I'm having is that the processor
page would shift the values of the columns one over. For example,
the value of column 4 would display as column 3 on the processor
page. Below is the code:
cfgrid page:
<cfform method="post" name="adcost"
action="index.cfm?fuseaction=process_advertising_cost_grid">
<cfgrid name="advertizingCosts"
format="HTML"
query="advertizingcosts"
selectMode="edit"
colHeaders="true"
colHeaderBold="yes"
width="600"
maxRows="25"
stripeRows="yes"
stripeRowColor="efefef"
>
<cfgridcolumn name="AdvertizingCostsID" header="ID"
width="20" select="no">
<cfgridcolumn name="AdvertizingCostsDate"
header="Advertizing Costs Date" mask="MMMM D, YYYY" width="160">
<cfgridcolumn name="Amount" header="Amount"
width="60">
<cfgridcolumn name="Details" header="Details">
<cfgridcolumn
name="StoreFrontName"
header="StoreFront"
width="150"
values="#ValueList(storefronts.StoreFrontCode)#"
valuesDisplay="#ValueList(storefronts.StoreFrontName)#"
>
</cfgrid>
<input type="submit" value="submit" class="button" />
</cfform>
processor page:
<cfif
IsDefined("form.advertizingCosts.RowStatus.Action")>
<cfloop index="counter" from="1"
to="#ArrayLen(form.advertizingCosts.RowStatus.Action)#">
<cfoutput>
<p>
counter is #counter#<br />
The row action for #counter# is
#form.advertizingCosts.RowStatus.Action[counter]#<br />
AdvertizingCostsID is
#form.advertizingCosts.AdvertizingCostsID[counter]#<br />
AdvertizingCostsDate is
#form.advertizingCosts.AdvertizingCostsDate[counter]#<br />
Amount is #form.advertizingCosts.Amount[counter]#<br
/>
Details is #form.advertizingCosts.Details[counter]#<br
/>
StoreFrontName is
#form.advertizingCosts.StoreFrontName[counter]#
</p>
<cfif #form.advertizingCosts.RowStatus.Action[counter]#
eq "U">
<pre>
Original AdvertizingCostsDate:
#form.advertizingCosts.Original.AdvertizingCostsDate[counter]#
Original Amount:
#val(form.advertizingCosts.Original.Amount[counter])#
Original Details:
#form.advertizingCosts.Original.Details[counter]#
Original StoreFrontName is
#form.advertizingCosts.Original.StoreFrontName[counter]#
</pre>
<cfelse>
</cfif>
</cfoutput>
</cfloop>
</cfif>
The Amount data would end up going to the details column, the
date appears as the amount on the second page. This page only
displays values.
It looks to be correct, but I'm not sure what is causing the
shifting.
Any help would be great!
JasonThis fixed it for me. Only do this if you have version 9.01 of coldfusion.
Open cfide/scripts/ajax/package/grid.js
find this line of code
var _5aa=$G.computeActualRow_editField(this.editFieldState,this.selectedRow); (IT is in the $G.Actions.afterEdit=function(_5a8))
change it to
var _5aa=$G.computeActualRow_editField(this.editFieldState,_5a8.row+1);
every thing should now be in sync -
Validate ascii value above a certain point javascript
Hi guys,
I'm wondering if it is possible to create a javascript function to validate within form items ascii values which are above a certain point, I would need to loop through the user input, through each character to check its ascii value but im unsure as to how to do this??
T.I.A
StefanHi,
Something like
function LoopStr(pStr){
var a;
var c=160;
for(i=0;i<=pStr.length;i++){
a=pStr.charCodeAt(i);
if(a>c){j=i+1;alert('String '+j+' character '+String.fromCharCode(a)+' is not allowed');return false;}
}Br,Jari -
How to find ASCII value of TAB ?
Hi Friends,
I am trying to find the ASCII value of the TAB character using the standard ASCII function like:
SELECT ASCII('<TAB>') FROM DUAL;
I am executing the above command in SQL*Plus.
It is not treating it as TAB.
It is treating it as space and giving ASCII value of Space -32.
Please let me know how to achieve this?
Database Version - 9i
Regards
Sreekanth Munagala.Well, evidently mine are smarter... :-)
SQL> select * from v$version;
BANNER
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
PL/SQL Release 9.2.0.8.0 - Production
CORE 9.2.0.8.0 Production
TNS for 32-bit Windows: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
SQL> select ascii(' ') from dual;
ASCII('')
9
SQL>
SQL> select * from v$version;
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> select ascii(' ') from dual;
ASCII('')
9
SQL> -
Ascii value of a non numeric string literal
hi,
i would like to get the ascii value of a non numeric string
having special characters from extended ascii set.
for example i have a user id "J��o M��" and i want to get the ascii value of each character in this string.
(There are special characters having ascii value more than 127, present in string literal)
if you know some methods to do that ??
thanksUse charAt(i) to give you each char in the string. A char is also the numeric value of the character: note that there's no such thing as "extended ASCII" -- ASCII is the first 128 characters of Unicode, and Java uses Unicode characters.
String str = "Hello";
for (int i = 0; i < str.length(); i++)
System.out.println((int) str.charAt(i)); // cast to int so the char is displayed as a number -
Hi ,
I was wondering if someone is still awake and can help me out here. I am trying to do Right Shift operation on the attached values. I need to shift the values by 2 places to the Right.
for example, 1110011011111 will become 0011100110111.
meaning add two 0 at the front and remove the last 2 digit.
Attachments:
shifting values.vi 9 KB
shifting values.vi 9 KBIs that your actual data? A sequence of the characters "1" and "0" (not the actual numbers 0 and 1), with tabs in between? The Logical Shift function only works with numbers. So, if that's your actual data, you first need to convert it to an array of numbers, and then you can use the Logical Shift function. You can convert the string to an array using the Spreadsheet String to Array and then use Scan From String to convert the sequence of character to a number.
EDIT: Was creating my response while RF was posting his reply.
Attachments:
shifting values_BD.png 4 KB -
hello everybody,
how can i find the ascii value of "&" in oracle database using sql query.your help highly appreciated.
thanks.Just adding to what others already suggested - use of CHR function ... although this is not needed for this post
This is just the reverse of the ASCII function.
Please check this query to understand what it does...
SELECT ASCII('&'), CHR(38) from dual;Ranit B. -
How to find the ASCII value of ' ?
how to find the ASCII value of ' using ASCII Function in SQL??
while i am trying this using syntax ASCII(''') the query is terminating at the second oneLokanath Giri wrote:
For your validation check this link
http://www.techonthenet.com/ascii/chart.php
Please don't just refer people to other non-oracle websites when the answer is so simple to give here as others have already done. -
Read binary and ascii values from input stream
Hi All
I want to read a stream that consist both binary values and ascii values. Length of the stream cannot anticipate. Can you help me?
ThanksSameera wrote:
Hi All
I want to read a stream that consist both binary values and ascii values. Length of the stream cannot anticipate. Can you help me?
ThanksHave a look at this:
Character and Byte Streams
http://java.sun.com/docs/books/tutorial/i18n/text/stream.html
Maybe you are looking for
-
HP Mini 210-1102TU Wont Accept 2GB ddr3 no boot.
Goo day! I recently bought this laptop HP MINI 210-1102tu Specs -atom n475 -1gb DDR3 -250gb hd This is my replacement with my 1year old hp mini 110 n280. My problem/our problem is this. It seems we CANT upgrade the memory into 2gb ddr3 1066 single st
-
NEED HELP ITUNES FREEZES WHEN OPENED PLEASE HELP
hello all whenever i open itunes on my macbook, the loading pinwheel comes up and doesn't go away until i quit itunes or turn off my computer. my itunes will 'freeze' whenever i open it and will not let me play songs or anything. please help me!
-
How do I stop cover flow from rotating????
How do I stop cover flow from rotating, I have switched it off but it still rotates. Phil
-
Hi, I am using the ABAP class and method in the workflow task. The task is going under error every time. If i am passing the same data to the funciton module inside the method it works fine. What could be the cause for this? The Task is having no s
-
Hi there, I have recorded an interview but a problem I have is that there is feedback coming through from a cell phone. The noise is that of a beeping like when a cell phone is connecting to a base station. I want to remove this from the interview. A