Manipulating single characters inside a string?
Hello CF Experts,
I feel a little stupid having to ask this, but I might be suffering from mental block:
I need to manipulate single characters inside a string. Lets say I have a string "-----" (5 hyphens) and
I want to replace the hyphen at position #pos# with "X".
I tried using the Mid() function, but that apparently is read-only:
<cfset Mid(string,#pos#,1) = "X">
results in an error.
Of course I can do string concatenation like
<cfset string = Mid(string,1,#pos#-1) & "X" & Mid(string,#pos#+1,Len(string)-#pos#)
or use the Insert/RemoveChars functions:
<cfset string = Insert("X",string,#pos#-1)>
<cfset string = RemoveChars(string,#pos#+1,1)>
but this seems awfully awkward.
There must be a more elegant solution. Any hints?
Regards, Richard
Strings are immutable, so one can't "edit" one, all one can do is create a new one based on an existing one. So your insert() / removechars() approach is fine. Or one could use left() & mid() (or right()), or replace() or... all variations on a fairly similar theme.
(http://en.wikipedia.org/wiki/Immutable_object#Java)
Adam
Similar Messages
-
How do I pass single quotes into a string variable?
Thanks for any help?
Example
Select xdat, yday
from foo
where
xdat = to_char(sysdate, 'mm/dd/yyyy')
How do I pass the single quoted stuff above into a string variable?Thank you but that is not the same thing. I am building a dynamic sql statement and need to pass the quoted material into a statement that is quoted Is that not what my example above shows?
My example above has a quoted string inside a string. I think this is exactly what you were asking for. -
RegExp for excluding special characters in a string.
Hi All,
Im using Flex RegExpValidator. Can anyone suggest me the correct expression to validate this condition?....
I have tried this expression :----- /^[^///\/</>/?/*&]+$/...But in this it is also negating the alphabets.Also I have tried with opposite condition that in the String we should have alphabets and the expression is:-- ([a-z]|[A-Z]|[0-9]|[ ]|[-]|[_])*..... Please can anyone help me on this.
Thanks in advanced to all.
Munirasorry but you are posting things back that do not make any sense
what do you mean with the below comment?
munira06 wrote:
Yes you are correct ,but I have tried this with single special character
say
Re: RegExp for excluding special characters in a string.
here is a sample app taken from the live docs
using ^[a-zA-Z0-9 \-_]*$ as the regex accepts all characters from a-z, A-Z, 0-9 - [space] and_
run the example tell me what regex you are using and what test strings fail when they should pass or pass when they should fail
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate the RegExpValidator. -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.events.ValidationResultEvent;
import mx.validators.*;
// Write the results to the
private function handleResult(eventObj:ValidationResultEvent):void {
if (eventObj.type == ValidationResultEvent.VALID) {
// For valid events, the results Array contains
// RegExpValidationResult objects.
var xResult:RegExpValidationResult;
reResults.text = "";
for (var i:uint = 0; i < eventObj.results.length; i++) {
xResult = eventObj.results[i];
reResults.text=reResults.text + xResult.matchedIndex + " " + xResult.matchedString + "\n";
} else {
reResults.text = "";
]]>
</fx:Script>
<fx:Declarations>
<mx:RegExpValidator id="regExpV"
source="{regex_text}" property="text"
flags="g" expression="{regex.text}"
valid="handleResult(event)"
invalid="handleResult(event)"
trigger="{myButton}"
triggerEvent="click"/>
</fx:Declarations>
<s:Panel title="RegExpValidator Example"
width="75%" height="75%"
horizontalCenter="0" verticalCenter="0">
<s:VGroup left="10" right="10" top="10" bottom="10">
<s:Label width="100%" text="Instructions:"/>
<s:Label width="100%" text="1. Enter text to search. By default, enter a string containing the letters ABC in sequence followed by any digit."/>
<s:Label width="100%" text="2. Enter the regular expression. By default, enter ABC\d."/>
<s:Label width="100%" text="3. Click the Button control to trigger the validation."/>
<s:Label width="100%" text="4. The results show the index in the text where the matching pattern begins, and the matching pattern. "/>
<mx:Form>
<mx:FormItem label="Enter text:">
<s:TextInput id="regex_text" text="xxxxABC4xxx" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Enter regular expression:">
<s:TextInput id="regex" text="ABC\d" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Results:">
<s:TextInput id="reResults" width="100%"/>
</mx:FormItem>
<mx:FormItem >
<s:Button id="myButton" label="Validate"/>
</mx:FormItem>
</mx:Form>
</s:VGroup>
</s:Panel>
</s:Application> -
Replace multiple characters in a string
Hi, I have some string fields that contain special characters such as ô and û and I want to replace them with ō and ū, and their upper case equivalents as well. How do I write a single formula that would find any of these characters in a string and replace them?
Thanks,
Willreplace(replace(replace(replace(x,'ô','ō'),'û','ū'),'Ô','Ö'),'Û','Ü');
where x is the string field. I suggest using the unicodes rather than the actual character. I do not think that I have the correct uppercase characters. Please ensure that they are correct in your formula. -
Finding location of single quote ( ' ) in a string
Hi,
I have a need to find the location of second single quote in a string.
Below query works fine for a string without single quote. It gives me the location of word 'HIER' for 2nd occurrence.
select instr('HIER A HIER B','HIER',2) from dual
I want to do the same with single quote. I am trying with the below query.
select instr('HIER A '' HIER B ''',chr(39),2) from dual
But it always gives me the location of first occurrence of single quote and not the second.
Any idea about this issue..?
Thanksselect regexp_replace('AND ( ACCT_V.HIER_NODE_NM = ''D0100'' AND TODAYS_DATE IS NULL ','.*''(.*)''.*','\1') from dual
select substr('AND ( ACCT_V.HIER_NODE_NM = ''D0100'' AND TODAYS_DATE IS NULL ',instr('AND ( ACCT_V.HIER_NODE_NM = ''D0100'' AND TODAYS_DATE IS NULL ','''')+1,instr('AND ( ACCT_V.HIER_NODE_NM = ''D0100'' AND TODAYS_DATE IS NULL ','''',1,2)-instr('AND ( ACCT_V.HIER_NODE_NM = ''D0100'' AND TODAYS_DATE IS NULL ','''')-1) from dualComment to the second approach: check SUBSTR() syntax, the second numeric parameter is length of the fragment, not the ending position. Still, RE approach is way shorter and more readable, isn't it? ;) -
How to see Greek characters inside a PDF report (made with XML Publisher)
Hi,
I just patched my e Business Suite (ver. 11.5.9) in order to use XML Publisher 5.6.3.
It works fine, but I have a big problem when I want to see Greek characters inside my report; instead to see the Greek characters I see only '?????'
I tried to add some font under the XML Publisher Administrator responsibility following the Doc ID: 373377.1 "How To Install a Font Using XML Publisher Administrator", but my problem remains: I don't see my Greek characters
Do I need to add any other fonts on the file system ? and where ? (under which path), or I set something at the XML Publisher Administrator responsibility level (under the Administration link) ?
Any help will be appreciated, because it's very urgent to know how to fix this problem.
Thanks in advance
AlexAlex,
Please verify the value of $AF_CLASSPATH variable and make sure that JRE_TOP/lib/fonts is part of this env variable (in addition to $CLASSPATH).
Note: 353164.1 - Chinese Characters Appear as Question Marks(?) When Using a Data Template
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=353164.1
Note: 399518.1 - Arabic Characters Appear As Question Marks
https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=399518.1 -
How to count number of repeated characters in a String
I have a String.... 10022002202222.
I need to know how many 2's are there in the string... here the string contains eight 2's..
Thanks in advance..it is workingYes, but... attention to surprises...
SQL> var v1 varchar2(1000);
SQL> exec :v1 := 'How to count the number of occurences of a characters in a string';
PL/SQL procedure successfully completed.
SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
6
SQL> exec :v1 := 'cccccc';
PL/SQL procedure successfully completed.
SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
SQL> select length(:v1) - nvl(length(replace(:v1,'c')),0) from dual;
LENGTH(:V1)-NVL(LENGTH(REPLACE(:V1,'C')),0)
6
SQL> -
How to search special characters in a string
Hi all,
I want to search special characters in all string columns and all rows in the table.
The table has about 5 string columns and about 5.000.000 rows. For each row and column, I have to search entries, which included special characters like ", !, ? or something else (f.ex. "Mama?Mia" or "!!!Hotel out of order!!!"). The problem, the character could stand at each position in the string.
What's the best and most performance possibility to search such entries?? Is it possibility only by SQL; is there a special function for this?? Or must I use PL/SQL.
Thanks for helping
DanaHTH
Laurent Schneider
OCM DBA
SQL> select * from z;
S
Mama?Mia
a b c
123
SQL> select * from z where translate(s,'~ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz1234567890','~') is not null;
S
Mama?Mia
SQL> select * from z where regexp_like(s, '[^[:alnum:][:space:]]');
S
Mama?Mia -
How do I drop the last 3 characters in a string?
Hello. I'm trying to find a way to drop the last 3 characters in a string. The length varies because it is a last name field. The problem is that when a customer has a suffix on their name, III for example, it is appended to the last name all in the last name field. If I use the ProperCase function, I end up with "Smith Iii". How can I tell it to drop the last 3 characters? I'll then append an UpperCase edition of the last 3 characters to that. Thank you!
Use the instring and right string functions then UpperCase
-
How to find out if there are repeated characters in a string
hey guys
well i kinda have a little problem figuring out how to find out
if there are repeated characters in a string.
if anyone can help, would appreciate it.
thanks
milosTry using the StringTokenizer class. if u already know which character to trace. this could do the job.
eg. String str = "here and there its everywhere";
StringTokenizer st = new StringTokenizer(str, "e");
int rep = st.countTokens(); -
Removing non english characters from my string input source
Guys,
I have problem where I need to remove all non english (Latin) characters from a string, what should be the right API to do this?
One I'm using right now is:
s.replaceAll("[^\\x00-\\x7F]", "");//s is a string having chinese characters.
I'm looking for a standard Solution for such problems, where we deal with multiple lingual characters.
TIA
NitinNitin_tiwari wrote:
I have a string which has Chinese as well as Japanese characters, and I only want to remove only Chinese characters.
What's the best way to go about it?Oh, I see!
Well, the problem here is that Strings don't have any information on the language. What you can get out of a String (provided you have the necessary data from the Unicode standard) is the script that is used.
A script can be used for multiple languages (for example English and German use mostly the same script, even if there are a few characters that are only used in German).
A language can use multiple scripts (for example Japanese uses Kanji, Hiragana and Katakana).
And if I remember correctly, then Japanese and Chinese texts share some characters on the Unicode plane (I might be wrong, 'though, since I speak/write neither of those languages).
These two facts make these kinds of detections hard to do. In some cases they are easy (separating latin-script texts from anything else) in others it may be much tougher or even impossible (Chinese/Japanese). -
Need help in replacing special characters in a string
Hi,
please let me know the best way to replace all the special characters in a string with space.
other than alphabets and numbers
with regards.
sumanth.please let me know the best way to replace all the special characters in a string with space.
other than alphabets and numbers
>
Sumanth Nag Kristam wrote:
> actually i need to replace hexa decimal char 0X1A in a string.... that is 'substitue' as per the chart
> any pointers....
>
> chk the link for the ASCII codes
> http://www.techonthenet.com/ascii/chart.php
But in Hexa decimal value there is no special characters? -
Sample code to identify special characters in a string
Hi,
I need to identify special characters in a string.... could anybody send me some code please.......
Thanks,
Best regards,
Karendata: str(100) type c.
data: str_n type string.
data: str_c type string.
data: len type i.
data: ofst type i.
str = '#ABCD%'.
len = strlen( str ).
do.
if ofst = len.
exit.
endif.
if str+ofst(1) co sy-abcde.
concatenate str_c str+ofst(1) into str_c.
else.
concatenate str_n str+ofst(1) into str_n.
endif.
ofst = ofst + 1.
enddo.
write:/ str.
write:/ str_c.
write:/ 'spacial chracter',20 str_n.
Function module <b>SF_SPECIALCHAR_DELETE</b> <b>DX_SEARCH_STRING</b>
l_address1 = i_adrc-street.
CHECK NOT L_ADDRESS1 IS INITIAL.
len = STRLEN( l_address1 ).
do len times.
if not l_address1+l(1) ca
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 '.
if i_adrc-street+l(1) CO sy-abcde.
elseif i_adrc-street+l(1) CO L_NUMCHAR.
exit.
endif.
l = l + 1.
enddo.
data : spchar(40) type c value '~!@#$$%^&()?...'etc.
data :gv_char .
data:inp(20) type c.
take the string length .
len = strlen (i/p).
do len times
MOVE FNAME+T(1) TO GV_CHAR.
IF gv_char CA spchar.
MOVE fnameT(1) TO inp2T(1).
ENDIF.
T = T + 1.
enddo.
REPORT ZEX4 .
PARAMETERS: fname LIKE rlgrap-filename .
DATA: len TYPE i,
T TYPE I VALUE 0,
inp(20) TYPE C,
inp1(20) type c,
inp2(20) type c,
inp3(20) type c.
DATA :gv_char.
data : spchar(20) type c value '#$%^&*()_+`~'.
START-OF-SELECTION.
CONDENSE fname.
len = strlen( fname ).
WRITE:/ len.
DO len TIMES.
MOVE FNAME+T(1) TO GV_CHAR.
IF gv_char ca spchar.
MOVE fnameT(1) TO inpT(1).
ENDIF.
T = T + 1.
ENDDO.
CONDENSE INP.
write:/ 'Special Characters :', inp.
Rewards if useful..........
Minal -
Unable to read more than 255 characters in a string data type.
Hello,
I am using Crystal Reports version 11.5.8.826 to generate reports from databases such as MS-Excel & BaaN.
In Excel, there are records which carry string lengths of more than 255 characters. All though the fields are getting displayed in the report, the data being displayed gets truncated once it reaches a length of 255 characters.
Kindly provide me with a solution this problem.
RegardsHello Manish,
I know that older versions of Crystal (Crystal 10 and older ) had a limitation of only 256 Characters for a string value. You should be able to use this code to get what you need.
We were successfully able to print out the Declaration of Independence through a Crystal report using something very similiar to this.
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
Shared StringVar Array strings;
Shared NumberVar arrayMax := 1;
Shared NumberVar maxLength := 250;
Shared BooleanVar firstTime := true;
Redim strings[arrayMax];
strings[1] := u201Cu201D;
u2018done!u2019
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
Here is my main loop that I used in the group header:
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
WhilePrintingRecords;
Shared StringVar Array strings;
Shared NumberVar arrayMax;
Shared NumberVar maxLength;
Shared BooleanVar firstTime;
Local StringVar enteredString;
Local NumberVar lenStr;
Local NumberVar lenArr;
Local NumberVar lenLeft;
enteredString := [Field Name];
enteredString := IIF(firstTime,enteredString, u201C, u201D & enteredString);
firstTime := false;
lenStr := Length(enteredString);
lenArr := Length(strings[arrayMax]);
lenLeft := maxLength u2013 lenArr;
if (lenLeft >= lenStr) then
strings[arrayMax] := strings[arrayMax] & enteredString;
u201D
else
strings[arrayMax] := strings[arrayMax] & left(enteredString, lenLeft);
arrayMax := arrayMax + 1;
redim preserve strings[arrayMax];
strings[arrayMax] := u201Cu201D;
strings[arrayMax] := strings[arrayMax] & right(enteredString, lenStr u2013 lenLeft);
u201D
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
and then to display the different sets in the text area. I would have one of these for every element I need displayed and change the display number variable.
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
Shared StringVar Array strings;
Shared NumberVar arrayMax;
Local NumberVar displayNumber := [element in array];
if(arrayMax >= displayNumber) then
strings[displayNumber];
else
u201D;
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
I like this version better because the array is completely dynamic. It can be as big or as small as it needs to be. There is always room for optimizations. But hopefully this will get you started on the right path.
Jenny -
Counting Characters in a string
HI all!
I am new working with java and i have an application where I have to count specific characters in a string e.g. 'a','.','H','4' and so on! I found an entry in the forum with this script:
String text = "Hello World!";
int count = 0;
for (int x = 0; x < text.length(); x++)
if (text.charAt(x) == 'l')
count++;
This Script count all the 'I', but I could not get CharAt to count different characters at once!
Is there a way?
Thx for your help!
LeBiteString text = "Hello World!";
int countl = 0;
int counto = 0;
for (int x = 0; x < text.length(); x++)
if (text.charAt(x) == 'l') countl++;
if (text.charAt(x) == 'o') counto++;
[/code[
Maybe you are looking for
-
Memory Mapping on a Virtual Machine
I have an application that memory maps a number of files. Occasionally it needs to unmap them so that they can be updated. On a real machine this process works flawlessly but I have two installs that are on virtual machines. On the virtual machine in
-
Question on HP PSC1350 and network printing
Hi. I have an HP PSC1350 connected to a windows XP computer. I found the printer on the mac through the network, but I'm not sure what driver I should use. I know that there isn't a 100% compatible driver, but I was wondering if anyone had any sugges
-
How do I install my plug-ins in Photoshop CS5 64bit
Can't seem to install my plug-ins that I have been using in Photoshop CS3 and CS4. Mediachance, Nik, onOne, Alien Skin, Photkit, Fluidmask, Fred Miranda, etc. They all work in CS3 in Win 7 Pro 64bit, but do not show in CS5.
-
How to take video on my mini ipad
can some one help on taking video from my ipad
-
Running multiple instances of Flash IDE CS(6)
I have a build machine compiling my fla files by running Flash.exe from command line and supplying a JSFL file as a parameter. I want to run multiple instances of Flash IDE in order to enable concurrent builds on that machine otherwise there's only o