Replace the first character in a String with blank
String a = dgramRsp.getAddress().toString();
a = a.replace('/','');The problem with the first statement is that it returns an ip address with a '/' in front of it. Like so.../192.168.0.190
I need to get rid of the '/'. The replace won't work because it wants a character between the ' '. Thanks for your time.
I had to think about it for a sec but yes you're
right.
InetAddress a = dgramRsp.getAddress();
String b = a.getHostAddress();
substring(1) would have worked, too, but it would have been redundant (removing a previously added slash).
Similar Messages
-
Replacing a special character in a string with another string
Hi
I need to replace a special character in a string with another string.
Say there is a string - "abc's def's are alphabets"
and i need to replace all the ' (apostrophe) with &apos& ..which should look like as below
"abc&apos&s def&apos&s are alphabets" .
Kindly let me know how this requirement can be met.
Regards
SukumariREPLACE
Syntax Forms
Pattern-based replacement
1. REPLACE [{FIRST OCCURRENCE}|{ALL OCCURRENCES} OF]
pattern
IN [section_of] dobj WITH new
[IN {BYTE|CHARACTER} MODE]
[{RESPECTING|IGNORING} CASE]
[REPLACEMENT COUNT rcnt]
{ {[REPLACEMENT OFFSET roff]
[REPLACEMENT LENGTH rlen]}
| [RESULTS result_tab|result_wa] }.
Position-based replacement
2. REPLACE SECTION [OFFSET off] [LENGTH len] OF dobj WITH new
[IN {BYTE|CHARACTER} MODE].
Effect
This statement replaces characters or bytes of the variable dobj by characters or bytes of the data object new. Here, position-based and pattern-based replacement are possible.
When the replacement is executed, an interim result without a length limit is implicitly generated and the interim result is transferred to the data object dobj. If the length of the interim result is longer than the length of dobj, the data is cut off on the right in the case of data objects of fixed length. If the length of the interim result is shorter than the length of dobj, data objects of fixed length are filled to the right with blanks or hexadecimal zeroes. Data objects of variable length are adjusted. If data is cut off to the right when the interim result is assigned, sy-subrc is set to 2.
In the case of character string processing, the closing spaces are taken into account for data objects dobj of fixed length; they are not taken into account in the case of new.
System fields
sy-subrc Meaning
0 The specified section or subsequence was replaced by the content of new and the result is available in full in dobj.
2 The specified section or subsequence was replaced in dobj by the contents of new and the result of the replacement was cut off to the right.
4 The subsequence in sub_string was not found in dobj in the pattern-based search.
8 The data objects sub_string and new contain double-byte characters that cannot be interpreted.
Note
These forms of the statement REPLACE replace the following obsolete form:
REPLACE sub_string WITH
Syntax
REPLACE sub_string WITH new INTO dobj
[IN {BYTE|CHARACTER} MODE]
[LENGTH len].
Extras:
1. ... IN {BYTE|CHARACTER} MODE
2. ... LENGTH len
Effect
This statement searches through a byte string or character string dobj for the subsequence specified in sub_string and replaces the first byte or character string in dobj that matches sub_string with the contents of the data object new.
The memory areas of sub_string and new must not overlap, otherwise the result is undefined. If sub_string is an empty string, the point before the first character or byte of the search area is found and the content of new is inserted before the first character.
During character string processing, the closing blank is considered for data objects dobj, sub_string and new of type c, d, n or t.
System Fields
sy-subrc Meaning
0 The subsequence in sub_string was replaced in the target field dobj with the content of new.
4 The subsequence in sub_string could not be replaced in the target field dobj with the contents of new.
Note
This variant of the statement REPLACE will be replaced, beginning with Release 6.10, with a new variant.
Addition 1
... IN {BYTE|CHARACTER} MODE
Effect
The optional addition IN {BYTE|CHARACTER} MODE determines whether byte or character string processing will be executed. If the addition is not specified, character string processing is executed. Depending on the processing type, the data objects sub_string, new, and dobj must be byte or character type.
Addition 2
... LENGTH len
Effect
If the addition LENGTH is not specified, all the data objects involved are evaluated in their entire length. If the addition LENGTH is specified, only the first len bytes or characters of sub_string are used for the search. For len, a data object of the type i is expected.
If the length of the interim result is longer than the length of dobj, data objects of fixed length will be cut off to the right. If the length of the interim result is shorter than the length of dobj, data objects of fixed length are filled to the right with blanks or with hexadecimal 0. Data objects of variable length are adapted.
Example
After the replacements, text1 contains the complete content "I should know that you know", while text2 has the cut-off content "I should know that".
DATA: text1 TYPE string VALUE 'I know you know',
text2(18) TYPE c LENGTH 18 VALUE 'I know you know',
sub_string TYPE string VALUE 'know',
new TYPE string VALUE 'should know that'.
REPLACE sub_string WITH new INTO text1.
REPLACE sub_string WITH new INTO text2. -
How to replace a character in a string with blank space.
Hi,
How to replace a character in a string with blank space.
Note:
I have to change string CL_DS_1===========CM01 to CL_DS_1 CM01.
i.e) I have to replace '=' with ' '.
I have already tried with <b>REPLACE ALL OCCURRENCES OF '=' IN temp_fill_string WITH ' '</b>
Its not working.Hi,
Try with this..
call method textedit- >replace_all
exporting
case_sensitive_mode = case_sensitive_mode
replace_string = replace_string
search_string = search_string
whole_word_mode = whole_word_mode
changing
counter = counter
exceptions
error_cntl_call_method = 1
invalid_parameter = 2.
<b>Parameters</b> <b> Description</b> <b> Possible values</b>
case_sensitive_mode Upper-/lowercase false Do not observe (default value)
true Observe
replace_string Text to replace the
occurrences of
SEARCH_STRING
search_string Text to be replaced
whole_word_mode Only replace whole words false Find whole words and
parts of words (default
value)
true Only find whole words
counter Return value specifying how
many times the search string
was replaced
Regards,
Jayaram... -
The first character in a string
I need to return the first character of a string, convert it to an integer, and compare it with another integer to see if they're the same. Sounds simple, even for me, but it won't work!!!
// First question >
Object userValue1 = JOptionPane.showInputDialog("Blah Blah Blah", JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
Variables.placeholder = (int) userValue1.charAt(0);This is the error I get
C:\Documents and Settings\imholt\My Documents\OOPAttempt\21_Questions\Engine.java:170: cannot resolve symbol
symbol : method charAt (int)
location: class java.lang.Object
Variables.placeholder = (int) userValue1.charAt(0);
^
1 error
I have a sneaky suspicion that once I find out what the problem was, I will ask myself why I didn't see it before...Try this
Object userValue1 = JOptionPane.showInputDialog("Blah Blah Blah", JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
String str = userValue1.toString();
Variables.placeholder = (int) str.charAt(0); -
Replacing the same value in a string with varying values
If I have a string:
"%s is the %s I am referring to"
and - I want to replace the %s occurrences with DIFFERENT values... what's the best way to do this.
I was thinking parsing it into seperate strings using substr and instr but, I'm not sure if that's overkill or not.
Replace is ideal but - it replaces every occurrence so - you can state just replace the first occurrence with one value and the second with another (i.e. if the desired result after replacing the above string was supposed to be "This is the string I am referring to"
Any help is appreciated.
ThanksHi,
wtlshiers wrote:
If I have a string:
"%s is the %s I am referring to"
and - I want to replace the %s occurrences with DIFFERENT values... what's the best way to do this.Whenever you have a question, please post CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data.
Explain how you get those results from that data.
Always say which version of Oracle you're using (e.g. 11.2.0.3.0).
See the forum FAQ {message:id=9360002}
I was thinking parsing it into seperate strings using substr and instr but, I'm not sure if that's overkill or not.Depending on your requirements, you might need to do that.
Replace is ideal but - it replaces every occurrence so - you can state just replace the first occurrence with one value and the second with another (i.e. if the desired result after replacing the above string was supposed to be "This is the string I am referring to"As you said, REPLACE changes all occurrences. There's no way to tell it (for example) to change only the first one.
REGEXP_REPLACE, is a lot more flexible. It does have an option for giving a specific occurrence, but you may not even need that feature. You might just want something like
REGEXP_REPLACE ( '%s is the %s I am referring to'
, '(.*)%s(.*)%s(.*)'
, '\1This\2string\3'
)It all depends on your data and your requirements.
Are the new values (such as 'This' and 'string') fixed, or can they change from row to row?
Will you always have 2 (or some known number) of '%s's in the original string?
Does '%' always signal something that is to be replaced? If not, how can you tell when it does and when it doesn't?
Does 's' always come right after '%'? If not, what are the possibilites, and what do the different characters signify? -
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 -
Any easier way to replace the last character of a string?
this is what I got:
select SUBSTR('tjgb005dy_01_31_08',1,LENGTH('tjgb005dy_01_31_08')-1)||'1' from dual;
tjgb005dy_01_31_01and I am not quite fond of it. it looks ugly and it is long.
so, I wonder if you guys have better ideas?
Thanks(Perhaps with replace there is no easier solution than the primary posted.)Well, look where I ended up...
SQL> -- generating sample data:
SQL> with t as ( select 'tjgb005dy_01_31_08' str from dual union
2 select 'tjgb005dy_01_31_03' from dual union
3 select '888888888888888888' from dual
4 )
5 --
6 -- actual query
7 --
8 select str
9 , case
10 when substr(str, -1) = 8
11 then
12 substr(str, 1, length(str)-1)||'1'
13 else
14 str
15 end
16 from t;
STR CASEWHENSUBSTR(STR,-1)=8THENSU
888888888888888888 888888888888888881
tjgb005dy_01_31_03 tjgb005dy_01_31_03
tjgb005dy_01_31_08 tjgb005dy_01_31_01Now I'm going to stay at the coffee-machine for the rest of the day... ;) -
TestStand database logging problem: only the first character is put in the table.
I am using TestStand 2.0.1 and Microsoft SQL server database. There is a weird problem when I use database logging. At first, all the database logging ran good.
Then one day after I moved the test equipment to production line, TestStand only logs the first character of each string field in the tables! There is no error message.
I setup another SQL server running locally on the same machine as the TestStand is and move the database to the local server, database logging has no problem. Schemas in TestStand Dabasebase Options are the same.
I tried to run TestStand from another computer on the network. There was no problem before, too. But now, TestStand always shows a Run-time error message like this:
Details:
An exception occurred calling 'LogResults' in 'ITSDBLog' of 'DBLog 1.0 Type Library'
An error occurred executing a statement.
Schema: New.
Statement: STEP_RESULT.
Connection failureMultiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
Source: TSDBLog
Error Code:
-2147467259; User-defined error code.
Location:
Step 'Log Results to Database' of sequence 'Log To Database' in 'Database.seq'
I have checked that the connection is good and also the table UUT_RESULT has been logged correctly.
Anyone can help?
Thanks.Thank you very much, Santiago.
Yes, I have a customized schema, but it is based on the pre-existing schema. I tried the schema:TS 1.x Access/SQL (NI), which came with TestStand, the results were the same.
I have tried to run different sequences. On one computer, I always get only the first character of each string entry logged in the remote database, however for the local server, everything is fine. On the other computer, there is no local SQL server, I always get similar error message as I mentioned in my post. The sequence step reports error is "Log Results to Database".
Any more suggestion?
Thanks again.
Best regards,
Jaso -
[CS2/CS3 JS] Finding the first character of each paragraph
Hi,
Can anybody help with my script below:
for (h=0; myParaCount>h; h++){
myChars = myStory.paragraphs.item(h).contents;
if (myChars.characters.item(0) == "l" && myChars.characters.item(0).appliedCharacterStyle == CharStyleWin){
myStory.paragraphs.item(h).appliedParagraphStyle = "L-B";
This script is supposed to test if the first character is an "l" with my character style "Wingdings" applied to it. I could not test whether the character style is "Wingdings" or not. What could be wrong with my script. Thanks.// You need to have a textFrame selected
var myFrame = app.selection[0];
var myParaCount = myFrame.paragraphs.length;
// There must exist a paragraphStyle name L-B
var myApplyStyle = app.activeDocument.paragraphStyles.item("L-B")
for (h=0; h < myParaCount; h++){
var myChar = myFrame.paragraphs.item(h).characters.firstItem();
// check if first char is "l" and if its applied charstyle name is CharStyleWin
if (myChar.contents == "l" && myChar.appliedCharacterStyle.name == "CharStyleWin"){
myFrame.paragraphs.item(h).appliedParagraphStyle = myApplyStyle;
/* Edited at 11.21 */ -
Please Help: Ignore first Character in a String.
How do you ignore the first Character in a String?
String a = JTable.getValueAt(row,column).toString();
//Ignore first Char of a? ('$')
double b = Double.valueOf(a).doubleValue();Any help would be appreciated!Ok,so I do that. Now I have the Char '$'. But I don't want '$', I want everything after it. Must I loop throught the rest of the string or can I just remove the first Char?
-
Can I disable the InDesign Lock File or replace the beginning character (tilde) so it is compatible with SharePoint?
Can I disable the InDesign Lock File or replace the beginning character (tilde) so it is compatible with SharePoint?
-
Only display the first character issue
Hi,
I'm using CR 2008 to generate reports.
I use oracle database.
I use a stored procedure to get data and everything working fine ,it return correct data.
I have five details section but i display one details section and i suppress others
My issue is execute the rpt file to presssig F5 key; string type record is only able to print the first character on the preview.
eg: record with value 'ABCDE', after printed on rpt file, only character 'A' was printed on the preview.
if i verify database, it display correct data but a few times later problem occurs again
Anyone know how to fix it?if you create a blank report as follows , you will take same error
my reports section;
section - formula fieds
a - - - - a b f g
b - - - - a b e f g
c - - - - a b c e f g
d - - - - c f g
e - - - - d e f g
my details sections suppress formula;
if {CR_TEST.CODE}=1 then false else true
if {CR_TEST.CODE}=2 then false else true
if {CR_TEST.CODE}=3then false else true
if {CR_TEST.CODE}=4 then false else true
if {CR_TEST.CODE}=5 then false else true
my procedure is just like this;
CREATE OR REPLACE PROCEDURE CR_TEST(
P_MONTH IN VARCHAR2
, P_YEAR IN VARCHAR2
, CODE IN NUMBER
, P_CURSOR OUT GP.REF_CURSOR
IS
BEGIN
IF CODE = 1
THEN
OPEN P_CURSOR FOR
SELECT A
, B
, 'X' C
, 'X' D
, 'X' E
, F
, G
, CODE CODE
FROM CR_TEST_TABLE
--WHERE conditions
ELSIF CODE = 2
THEN
--A, B, E, F, G
OPEN P_CURSOR FOR
SELECT A
, B
, 'X' C
, 'X' D
, E
, F
, G
, CODE CODE
FROM CR_TEST_TABLE
--WHERE conditions
ELSIF CODE = 3
THEN
OPEN P_CURSOR FOR
SELECT A
, B
, C
, 'X' D
, E
, F
, G
, CODE CODE
FROM CR_TEST_TABLE
--WHERE conditions
ELSIF CODE = 4
THEN
OPEN P_CURSOR FOR
SELECT 'X' A
, 'X' B
, C
, 'X' D
, 'X' E
, F
, G
, CODE CODE
FROM CR_TEST_TABLE
--WHERE conditions
ELSIF CODE = 5
THEN
OPEN P_CURSOR FOR
SELECT 'X' A
, 'X' B
, 'X' C
, D
, E
, F
, G
, CODE CODE
FROM CR_TEST_TABLE
--WHERE conditions
END IF;
END;
Edited by: assaulter on Oct 12, 2011 11:50 AM
Edited by: assaulter on Oct 19, 2011 1:50 PM -
Even more about deleting the first word in a string
hi, i have this code that removes the first word in a string, returns the shorter string, removes the first word from the shorter string aso... what i would like it to do is to stop when it hits a non-character, but i can't get it to do that. does anyone know why \b won't work?
import java.io.*;
class Testar {
public static void main(String[] args) {
String partDesc = "Hi my name is SandraPandra.";
while (partDesc.equals("\b") == false) { //this is where something goes wrong
System.out.println(partDesc);
partDesc = partDesc.replaceFirst("^(\\w+)\\s+","");
} thanx in advance!while (partDesc.equals("\b") == false) That compares partDesc to a string consisting of one backspace character. I suspect you're trying to use the regex word-boundary anchor, but that's a dead end. If you want to stop beheading the string when the regex stops matching, you can write the code exactly that way: class Testar {
public static void main(String[] args) {
String partDesc = "Hi my name is SandraPandra.";
while ( partDesc.matches("^(\\w+)\\s+.*") ) {
partDesc = partDesc.replaceFirst("^(\\w+)\\s+","");
System.out.println(partDesc);
} If performance is a concern, you can use a pre-compiled Pattern object for greater efficiency. Thanks to Matcher's lookingAt() method, you can use the same regex for the test and the replacement: class Testar {
public static void main(String[] args) {
String partDesc = "Hi my name is SandraPandra.";
Pattern p = Pattern p = Pattern.compile("^(\\w+)\\s+");
Matcher m = p.matcher(partDesc);
while ( m.lookingAt() ) {
partDesc = m.replaceFirst("");
System.out.println(partDesc);
m.reset(partDesc);
} The ^ anchor isn't really necessary in this version, since lookingAt() implicitly anchors the match to the beginning of the string, but you might as well leave it in. -
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! :) -
Replacing the default field in a menu with text
Using DW MX2004, ASP/VBScript and Access
In a form that's intended for updating records I'm using a
menu from which a category can be selected from a list. At present
the menu loads with the first category name on the list. I want to
replace this with text, e.g. "Select a Category." to force people
to make a choice. The code I'm using is below and was produced
using the Record Insertion Form Wizard.
ThanksHi,
wtlshiers wrote:
If I have a string:
"%s is the %s I am referring to"
and - I want to replace the %s occurrences with DIFFERENT values... what's the best way to do this.Whenever you have a question, please post CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data.
Explain how you get those results from that data.
Always say which version of Oracle you're using (e.g. 11.2.0.3.0).
See the forum FAQ {message:id=9360002}
I was thinking parsing it into seperate strings using substr and instr but, I'm not sure if that's overkill or not.Depending on your requirements, you might need to do that.
Replace is ideal but - it replaces every occurrence so - you can state just replace the first occurrence with one value and the second with another (i.e. if the desired result after replacing the above string was supposed to be "This is the string I am referring to"As you said, REPLACE changes all occurrences. There's no way to tell it (for example) to change only the first one.
REGEXP_REPLACE, is a lot more flexible. It does have an option for giving a specific occurrence, but you may not even need that feature. You might just want something like
REGEXP_REPLACE ( '%s is the %s I am referring to'
, '(.*)%s(.*)%s(.*)'
, '\1This\2string\3'
)It all depends on your data and your requirements.
Are the new values (such as 'This' and 'string') fixed, or can they change from row to row?
Will you always have 2 (or some known number) of '%s's in the original string?
Does '%' always signal something that is to be replaced? If not, how can you tell when it does and when it doesn't?
Does 's' always come right after '%'? If not, what are the possibilites, and what do the different characters signify?
Maybe you are looking for
-
How to move MobileMe Account to iCloud?
I tried logging in my iCloud account and got this message: "Go to me.com on your computer to move your information to iCloud". PRESS "OK" I did that by going to my pc and logged into www.me.com but somehow can't configure how to move MobileMe acco
-
I have a weird problem: in using a headset to make calls using Skype or iChat I cannot get the headset microphone to work, though the earphones work fine. Everything is plugged in correctly. Have selected the Line-In option in the Sound panel of Syst
-
Motion Export glitches - PLEASE HELP!!!!
I have had it with Motion. I am trying to export something that I have had done for 3 weeks and each time I export it a new glitch comes up on the export. For instance - graphics will be missing, video will all of the sudden gitter, and emitter will
-
Hello everyone. I recently have been reading into QOS and have been fiddling with it on my Linksys WRT54G router. But there are a few things that seem limiting (at least on this version) so I have some questions. I live in a house with three other ro
-
I recently upgraded both my imac and macbook pro to a new mac mini and macbook air. I have a networked (via airport extreme) canon ipf6100 printer that had been working great from my older computers (all running current mountain lion). The new comp