Picking character from a string
Hi guys
How to pick each character of a string containing few character without using a loop. Like "LabVIEW" will become a array of string "L","a","b" etc
Thanks in advance
Niladri
Why would you not want to use a loop?
You could use String Subset in a loop to get each byte.
You could alsoe use String to U8 array to get an array of bytes. Then convert that back to individual string characters by using the typecast function in a loop with autoindexing turned on.
Attachments:
Example_VI_BD.png 10 KB
Similar Messages
-
Strip the first character from a string
i am trying to strip the leftmost character from a string
using the following:
<cfset Charges.DTL_CHG_AMT_EDIT =
#Right(Charges.DTL_CHG_AMT_EDIT,Len(Charges.DTL_CHG_AMT_EDIT)-1)#>
i keep getting the following error:
Parameter 2 of function Right which is now -1 must be a
positive integer> RemoveChars() much easier than Right()? How so?
Semantically, if the object of the exercise is to *REMOVE
CHARacters from a
string* (which it is, in this case), it is simply better
coding to use
removeChars() rather than right(). That, and it's one less
function call
(the RIGHT() solution also requires a call to LEN() for it to
work).
So removeChars() is "easier" because it reflects the intent
of the exercise
directly, is simpler logic, is easier to read, and - I can't
be arsed
counting keystrokes - is probably less typing.
That'd be how.
Adam -
Replace a character from a string
Hi,
how can I replace a particular character from a string on a particular occurrence? Say for eg, if i wan to replace 'a' of second occurrence from 'abcabcabc', then what should i do? I guess the normal REPLACE function replaces every occurrence in a given string. So is there any other way to solve this?
Thanks!If you are in 9i:
Then you got to split the string into based on the nth position.
SQL> select replace('abddefabc','a','x') from dual;
REPLACE('
xbddefxbc
SQL> select instr('abddefabc','a',2) from dual;
INSTR('ABDDEFABC','A',2)
7
SQL> select substr('abddefabc',1,instr('abddefabc','a',2)-1),substr('abddefabc',instr('abddefabc','a',2)) from dual;
SUBSTR SUB
abddef abc
SQL> select substr('abddefabc',1,instr('abddefabc','a',2)-1),replace(substr('abddefabc',instr('abddefabc','a',2)),'a','X') as replaced from dual;
SUBSTR REP
abddef XbcOfcourse, later on you can join the string..
Jithendra -
How to get specific character from a string
I have a value such as: 0-5 or 123-30. This is a combination
from 2 different IDs.
All I need is to get the number on the right (5 from 0-5 OR
30 from 123), any number on the right of the "-" character not
including
the "-"
I'm not sure what ColdFusion function can I use safely.
I said safely since all I can find is either Left or Right
functions. With these 2 functions, I need to specify the number of
character to extract while in my case the application is growing so
the ID may currently be only 1 digit each (0-5) but later it may
grow longer (123-5677).
If anyone know the function, please help me. Thank you!Something like this?
Mid(string, Find("-",string)+1 ,
Len(string)-Find("-",string))
Since
Mid(string, start, count)
and
Len(string or binary object)
and
Find(substring, string [, start ])
Or perhaps ....
ListLast(string, "-")
since
ListLast(list [, delimiters ])
Phil -
Detect special character from a String
Hello guys,
Some of the files in unix box contain special characters . I need to strip these special character in the filename to underscore. however, I do not want to strip off special character like _ - ^ . @
Pattern escaper = Pattern.compile("([^a-zA-z0-9_-^.@])");
I couldn't strip off the caret. Appreciate any advice please. Thanks in advance!
Cheers,
MarkHi Alice,
I tried your suggestion:
public static void main(String[] args) throws IOException {
rename(args[0], args[0].replaceAll("[^a-zA-Z0-9\\\\/:@._^-]","_"));
public static void rename(String from, String to) throws IOException{
// File (or directory) with old name
File file1 = new File(from);
// File (or directory) with new name
File file2 = new File(to);
// Rename file (or directory)
boolean success = file1.renameTo(file2);
if (!success) { // File was not successfully renamed
System.out.println("failed to rename : " + file1);
C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1~2.txt
C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1^2.txt
failed to rename : C:\Apps\mud\12.txt
C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\[email protected]
C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1@2$-_3mn.txt
C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1@2$-_3mn.txt
failed to rename : C:\Apps\mud\1@2$-_3mn.txt
C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1@2$-_3m'n.txt
C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1@2$-_3m'^n.txt
failed to rename : C:\Apps\mud\1@2$-_3m'n.txt
C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1@2$-_3m'^n.txtbut however, whenever I put in a caret in the filename, it always failed to rename. Appreciate your further advice please. thanks in advance!
Cheers,
Mark -
Counting a Special Character from a String
Hello,
I have a String let say 'ABC-X', 'ABC-X-Y' ....
so how can we find the count/No. of Hypen('-') .. in a string....I have a String let say 'ABC-X', 'ABC-X-Y' ....
so how can we find the count/No. of Hypen('-') .. in a string....
SQL> var str varchar2(20);
SQL> exec :str := 'ABC-X-Y';
PL/SQL procedure successfully completed.
SQL> select length(:str) - nvl(length(replace(:str,'-')),0) from dual;
LENGTH(:STR)-NVL(LENGTH(REPLACE(:STR,'-')),0)
2
SQL> -
Get first character from a String
Hi!
I've got a problem with the login of my program:
I want to get the first character out of a String to select two types of users.
eg.
login "a20202" --> a --> first kind of user or
login "b20202" --> b --> second kind of user
Can you please help me?
Bye
LizAm I on way to challenge the Worst Code Awards 2004 ? Let me have a go ... It is a far superior code-generating version :)
Kept to ascii-range for the benefit of your monitor (and eyes):class NoMyWayIsFarSuperior {
public static void main(String[] args){
System.out.println("public static char getFirstChar(String message){");
for(int k = 0; k < 256; k++){
System.out.println(" if(message.charAt(0) == " + k + ") return '" + ( (char) k) + "';");
System.out.println(" throw new Exception(\"First char not within ascii range ... Please try again.\"); ");
System.out.println("}");
} The potential for optimisation is endless! :) -
How to remove certain character from a string?
Follows the table:
CT_TRABALH
400rj101
400rj102
400rj103
400rj104
400rj105
400rj106
400rj107
400rj108
400rj109
400rj1010
400rj1011
I woulld like to make the following with its values. For example the value 400rj1010
I would like to remove its last character (400rj101) and then relace the last zero for the last number(400rj111) by query. Is there any way I can achieve this?I would write something a little more generic :
SCOTT@demo102> with tbl as
2 (select '400rj101' as CT_TRABALH from dual union all
3 select '400rj102' from dual union all
4 select '400rj103' from dual union all
5 select '400rj104' from dual union all
6 select '400rj105' from dual union all
7 select '400rj106' from dual union all
8 select '400rj107' from dual union all
9 select '400rj108' from dual union all
10 select '400rj109' from dual union all
11 select '400rj1010' from dual union all
12 select '400rj10120' from dual union all
13 select '400rj14120' from dual union all
14 select '412rj14120' from dual union all
15 select '400rj1011' from dual )
16 select CT_TRABALH,
17 case when substr(CT_TRABALH,-1,1) = '0'
18 then decode(instr(substr(CT_TRABALH,1,length(CT_TRABALH)-1),0,-1),
19 0, substr(CT_TRABALH,1,length(CT_TRABALH)-1),
20 substr(CT_TRABALH,1,instr(substr(CT_TRABALH,1,length(CT_TRABALH)-1),0,-1)-1)
21 ||substr(CT_TRABALH,-2,1)
22 ||substr(CT_TRABALH,instr(substr(CT_TRABALH,1,length(CT_TRABALH)-1),0,-1)+1,
23 length(CT_TRABALH)-instr(substr(CT_TRABALH,1,length(CT_TRABALH)-1),0,-1)-1))
24 else CT_TRABALH
25 end as CT_TRABALH_0
26 from tbl;
CT_TRABALH CT_TRABALH_0
400rj101 400rj101
400rj102 400rj102
400rj103 400rj103
400rj104 400rj104
400rj105 400rj105
400rj106 400rj106
400rj107 400rj107
400rj108 400rj108
400rj109 400rj109
400rj1010 400rj111
400rj10120 400rj1212
400rj14120 402rj1412
412rj14120 412rj1412
400rj1011 400rj1011
14 rows selected.
SCOTT@demo102> Nicolas. -
Replace tab character from string in ABAP
hi experts,
I have a string like this "a<tab character>b<tab character>c<tab character>d". for my processing i want the output like "abcd". How can i replace all occurances of this tab character from my string.
tab character = a hexa decimal character. I dont know the hex value for this.
regards
Raghavhi you joined SCN in 2007 its a way long time to say.. ur new.. any ways.
after declaring the lv_tab as I said...
REPLACE ALL OCCURRENCES OF lv_tab in <string> with space. -
Getting one character at a certain position from a string array
Hi, i'm new at learning java, but have strong experience at C++ and asm. How would i get one character at a certain positon from a string array.
for example:
String Phrases[] = {"To be or not to be, that is the question","The Simpsons","The Mole","Terminator three rise of the machines","The matrix"};
that is my string array above.
lets say i wanted to get the first character from the first element of the array which is "T", how would i get thisok well that didn't work, but i found getChars function can do what i want. One problem, how do i check the contents of char array defined as char Inchar[];
-
NewLine Character in the String received from Interactive Adobe Form
Hello Experts,
Following is the issue we have with interactive Adobe Form
We have a text area within the form. User enters the text in multiple lines in this text area.
We are calling a backend function module designed in SE37 that accepts and process the data from the adobe form. We are also processing the string data user enters in the text area.
When we receive the string from the form, the newline character within the string is displayed as '#' in the debugger. We tried splitting this string using cl_abap_char_utilities=>newline and cl_abap_char_utilities=>cr_lf but NO luck. Though in the debugger we see cl_abap_char_utilities=>newline as '#' in the debugger and also '#' is present within the string, for some reason when string is processed to find cl_abap_char_utilities=>newline, we can find/locate it.
Because ABAP code is not able to identify the newline character within the string received from Adobe form, we are not able to maintain the formatting of the string as it was entered in the form.
Any help to resolve this issue is appreciated.
Thanks in Advance.
Regards,
BhushanHi Bhushan,
I was going through your issue, and I feel this is something you can do with scripting. Basically you should read whole string and find the new line character and replace with a space or comma, as per your requirment.
Do like following:
In the exit event of the field select java script and write following code:
var strng = this.rawValue;
strng.replace(/\n/g, " ");
above im reaplcing new line with a space.
I think it should work I have not tested it. Pls update if you test it .
Regards,
Ravi.D -
How can i Pick the data from the string
Hi Gurus
How can i Pick the data from the string using regular expressions. for ex:
1) 10000-san0001
2) 3000000-rani0001
3) 30-super003
its doesnt mainain how many characters.
like this i got string. now i only want after the symobl( -) text (san
rani
super) .how can i pick that
can anyone provide me regular expressions.
Thanks & Regards
Sandya
Edited by: sandya rani on Jan 29, 2010 2:51 PMREPORT ZTEST.
data: str1 TYPE string,
str2 TYPE string,
str3 TYPE string,
lenth TYPE string,
str4 TYPE string,
temp type i value '0'.
data: ii type i value '0',
jj type i value '1'.
Data : begin of itab OCCURS 0,
l_string type string,
end of itab.
itab-l_string = '3000000-GUNDALA20001'.
append itab.
clear itab.
itab-l_string = '2045677-iCVj1001'.
append itab.
clear itab.
itab-l_string = '3000-ragh30001'.
append itab.
clear itab.
loop at itab.
MOVE 0 TO ii.
MOVE 1 TO jj.
SPLIT itab-l_string AT '-' INTO: str1 str2 .
clear: itab-l_string,str1.
lenth = strlen( str2 ).
while temp < lenth.
str4 = str2+ii(jj).
if str4 CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' or str4 CA 'abcdefghijklmnopqrstuvwxyz'.
if sy-subrc = 0.
CONCATENATE str3 str4 into str3.
endif.
ii = ii + 1.
ENDIF.
temp = temp + 1.
ENDWHILE.
write: / str3.
clear: itab, ii, jj,str1, str2, str3, str4,temp, lenth.
Endloop. -
How do I convert an alpha character from a text string to its decimal value
I am trying to find out the actual decimal value of a character in a string. So far the code below is as far as I got. I am able to get what I guess is a byte value.
This is for a school assignment:
The idea behind what I am trying to do is to design a hash function to store dictionary words into a bucket array hash table, without using the existing Hashtable.class
so far this is what I can come up with to get some kind of value for each character in the string, however, what I am trying to get is the decimal value for each character.
public static void main(String args[]){
String word = "abcdefghijklmnopqrstuvwxyz";
for (int i=0 ; i < word.length(); i++){
System.out.print((word.substring(i,i+1)));
System.out.print("\t : "+((word.substring(i,i+1))).getBytes());
Thankyou for any replies.I'm not sure I completly understand your goal- what you mean by "decimal value", but, if you simply want to find the byte value of each character in a String, you would probably be better off using getBytes() in a way like this,
byte [] bytes = string.getBytes();
Then, if you need to map that to a charcter, you could use a for loop like
for (int x = 0; x < bytes.length; x++) {
table.put((char)bytes[x], bytes[x]);
which assummes this bucket class of yours allows primitive data types like so (in Hashtable or HashMap, you would have to use a wrapper Object). I guess, my point reduces to, don't use substring and string search methods (like indexOf()), unless you have to because they are more expensive then just maping the array of bytes and chars, which seems to be what you are interested in doing. -
Use of offset to pick character of string
hi all.
i wish to have 3rd and 4th character of a string and would wish to replace with other character.am i doing it correctly?
l_customer1 = l_customer+3(2).
will thisgive me new l_customer with 3rd and 4th character field,
Also suggest if i want to learn offset,replace and translate kind of stuff,how can i research.
thanks in advance.Try something like this:
DOMParser d = new DOMParser();
String x = "<x/>";
d.parse( new StringReader(x) );
null -
How can i store values from my String into Array
Hi guys
i wants to store all the values from my string into an array,,,, after converting them into intergers,,,, how i can do this becs i have a peice of code which just give me a value of a character at time,,,,charat(2)...BUT i want to the values from String to store in an Array
here is my peice of code which i m using for 1 char at time
int[] ExampleArray2 = new int[24];
String tempci = "Battle of Midway";
for(int i=0;i>=tempci.length();i++)
int ascii = tempci.charAt(i); //Get ascii value for the first character.public class d1
public static final void main( String args[] )
int[] ExampleArray2 = new int[24];
String tempci = "Battle of Midway";
for(int i=0;i<tempci.length();i++)
int ascii = tempci.charAt(i);
ExampleArray2=ascii;
for(int i=0;i<ExampleArray2.length;i++)
System.out.println(ExampleArray2[i]);
Maybe you are looking for
-
I Am looking for an app free app that will allow me to type and edit my homework. I am using a 7.1.1 version of I pad. I have a wireless printer from Walmart hp envy 4502 which is working great. Appreciate any input
-
Can't run JDeveloper 11.1.2.1 app on Weblogic 10.3.6
I'm trying to migrate my application developed in JDeveloper 11.1.1.4 (ADF BC, ADF Faces stack) to JDeveloper 11.1.2.1. This app was previously deployed to Weblogic 10.3.4. When I generate .ear file and try to deploy it with Enterprise Manger to Webl
-
Printing a barcode font no longer works properly
I have been using a true type font "3 of 9 barcode" to print mailing labels on an internal website using the following css for some time: .barcode { font-family: "3 of 9 Barcode", Times, serif; font-size:36px; } After upgrading to Firefox 5 it stoppe
-
I have copied code from one set of files that work and pasted them into another set of files and they do not work. The site I am developing is for an artist. You choose your medium and a field of pictures appear. When you choose an image it enlarg
-
Hi, I have a scenario where in during a production of main Finished Material, two co products will come out. These products undergo further processing and they can be sold and also these two co products are used to produce one more material (by produ