Appending a character to a string
Hi I am trying to read in a sequence of numbers from a file, theyre of the form: 0.034 0.113 0.987 etc. What i am trying to do is read in the line of these numbers, and if we are not at a space in the numbers or at the end of file I want to append the numbers to a stringbuffer called TempHelix. For some reason my program keeps getting an error inside my while loop. Any help is appreciated
StringBuffer TempHelix = null;
int index = 0;
if((current.charAt(index) != ' ') && index <current.length()){
//PROBLEM HERE
TempHelix = TempHelix.append(current.charAt(index));
//NOW WE GET THE STRING THAT HAS BEEN MADE UP IN THE
//LOOP AND PARSE TO A DOUBLE AND THEN INSERT INTO AN ARRAY
String s = new String(TempHelix);
TempDouble = Double.parseDouble(s);
Helix[index] = TempDouble;
index++
//after adding to index we go back into loop and continue
}
here is what i have modified so far:
double TempDouble = 0;
int index = 0;
if((current=dis.readLine()) != null){
StringBuffer TempHelix = new StringBuffer(null);
if((current.charAt(index)!= ' ')){
//PROBLEM HERE
TempHelix.append(current.charAt(index));
//TempHelix = TempHelix + current.charAt(index);
String s = TempHelix.toString();
TempDouble = Double.parseDouble(s);
Helix[index] = TempDouble;
System.out.println(Helix[index]);
index++;
}
Similar Messages
-
Putting a null character in a String?
Hi,
I need to send a null character through a nio channel. Specifically, it needs to be decoded from a String into a byte array. Can I append a null character to a String so that getBytes() method will return it? Thanks,
rankoThanks, I tried that but it doesn't work. I also
tried appending '\0' and an uninitialized character
which should by default have a value of a null
character. I tried creating a String out of a char
array that has one element containing a null character
but that did not work either. I guess that since null
characters end the String, you cannot actually add
them to the body of the String. Or is there a way?FYI, strings aren't null-terminated in Java. -
How to count number of occurences of a character in a string
I want to get the count of occurences of a character within a string. Is there any function for this or should i go for a PLSQL.
For example is the sting is "occurences" & if i search for character "c", the answer should be 3.
Regards,
Sunil.SQL> select length('occurence') - length(replace('occurence','c')) from dual;
LENGTH('OCCURENCE')-LENGTH(REPLACE('OCCURENCE','C'))
3 -
How to get each character in a string
as in 'C' we use arrays to get each character of a string stored in array.how can we get each character of a string stored in a variable.
Hi,
For that you need to do offset.
for example one variable called VAR contains string 'HUMERAH'.
if you want each character of that string then you need to decalre as many variable as the number of string.
like
data : var1(1),
var2(1),
var(3),
var(4).
var1 = var+(1).
var2 = var+1(1).
var3 = var+2(1).
var4 = var+3(1).
now var1,var2,var3,var4. contains the single characters.
Regards,
Guru
mark helpful answers -
Replacing a character in a string to another character
hi,
i need to write a function or procedure to replace the character of a string value suppose:
l_error:= 'abcdefghijklmnop' is a string
i need write a function or procedure to replace the character "c" to "z"
that data in l_error is not in any table.
thanks,
AJI want to Replace all the Existence of the word - "Test" in a string with "Test1" whereever a space exits before the word Test and someother alphabet after "Test" i.e. Test will be replaced with Test1 if a word starts with Test and contains more alphabets also. For example - TestName should be replaced with Test1Name while MyTest should not be updated to MyTest1.
I have tried to use below query which uses oracle regular expressions -
SELECT REGEXP_REPLACE('MYCOMPANY TEST TESTGEET INDIA PVT LTD TEST','\s(TEST)\w',' TEST1') FROM DUAL
Output -
"MYCOMPANY TEST *TEST1EET* INDIA PVT LTD TEST"
Here, it has also replaced the G also from TESTGEET and resulted in TEST1EET while i want TEST1GEET.
Can someone please suggest how can i do this..... may b m doing some silly mistake but sorry m a newbie to regular expression...
Thanks in advance.. -
Function in oracle to find number of occurances of a character in a string
hi,
is there any function in oracle to find the number of ocurrances of a character in a string ?
or is there any simple way of doing the same, rather than writting many lines of code as my program is already very complex.
MariaHi Maria,
I don't know of such a function in Oracle, but maybe you could use this:
length(search_string) - length(replace(search_string, character_to_be_found))
For example: select length('Hello') - length ( replace('Hello', 'l')) from dual;
Hope this is what you're looking for
Danny -
How to escape the character in a string?
I have the following code that is causing an error. I'm
attempting to use < (less than) character in a string that is
part of a dynamic query:
<cfif url.age eq 1>
<cfset askAge = " < 15">
<cfelseif url.age eq 10>
<cfset askAge = " Between 56 and 60">
<cfelseif url.age eq 11>
<cfset askAge = " > 60">
</cfif>
The error occurs as a result of the line <cfset askAge = "
< 15">. The > 60 works fine. What I need is to build the
SQL statement SELECT * FROM myTable WHERE age < 15
ColdFusion sets the string properly but when I try to run the
query I guess it thinks I'm trying to open a tag. The exact error
is:
The content beginning "< " is not legal markup. Perhaps
the " " () character should be a letter.
The content beginning "< " is not legal markup. Perhaps
the " " () character should be a letter.
I can't use the ASCII code for this character as the database
will obviously crap out.
Any help would be greatly appreciated and many thanks in
advance.
DaveDave,
What if you passed off the output of the lt/gt symbols to the
query itself?
Something like,
<cfif url.age eq 1>
<cfset compareOperator = "less"/>
<cfset askAge = "15">
<cfelseif url.age eq 10>
<cfset compareOperator = "between"/>
<cfset askAge = " 56 and 60">
<cfelseif url.age eq 11>
<cfset compareOperator = "greater"/>
<cfset askAge = "60">
</cfif>
Then in the query:
<cfquery name="qTest" datasource="dsn">
SELECT * FROM myTable
WHERE age
<cfswitch expression="#compareOperator#">
<cfcase value="less">
<
</cfcase>
<cfcase value="greater">
>
</cfcase>
<cfcase value="between">
BETWEEN
</cfcase>
<cfdefaultcase>
=
</cfdefaultcase>
</cfswitch>
#askAge#
</cfquery>
Probably a better way, at least a more efficient way, but
just a thought...cfswitch processed pretty quickly and this would
remove any issues with trying to use <> symbols.
Cheers,
Craig -
How to get a set of character within a string?
Hi,
I need to cut a set of character within a string. I have tried everthing but I need help.
Example.
Database Version 11.2.0.3
create table tst_string (message varchar2(600));
insert into tst_string values ('ANR0166I Inventory file expiration finished processing for node OSOGBO, filespace OSOGBO\SystemState, copygroup BACKUP and object type GROUP BASE with processing statistics: examined 43, deleted 43, retrying 0, and failed 0. (SESSION: 1506, PROCESS: 2)');
insert into tst_string values ('ANE4175I Starting Full VM restore of VMware Virtual Machine ''mfujiwara'' target node name=''VC1_DC1'', data mover node name=''VC1_DC1_DM3'' (SESSION: 3780)');
commit;
select * from tst_string;
MESSAGE
ANR0166I Inventory file expiration finished processing for node OSOGBO, filespace OSOGBO\SystemState, copygroup BACKUP and object type GROUP BASE with processing statistics: examined 43, deleted 43, retrying 0, and failed 0. (SESSION: 1506, PROCESS: 2)
ANE4175I Starting Full VM restore of VMware Virtual Machine 'mfujiwara' target node name='VC1_DC1', data mover node name='VC1_DC1_DM3' (SESSION: 3780)
## I want get
# From first line following values:
node OSOGBO
filespace OSOGBO\SystemState
examined 43
deleted 43
retrying 0
failed 0
# From second line
mfujiwara
VC1_DC1
VC1_DC1_DM3Any help can be useful...
Thanks in advance.Hi Frank,
It looks like message can be seen as delimited lsit of sub-messages, where a number of different characters (perhaps ',' amd ':') may serve as delimiters. Each sub-message may or consist (entirely or in part) of something you want to display.Yes. In my first case where is "ANR0166I" I want get the characteres before "," (e.g "OSOGBO," I want get "OSOGBO") excluding "(SESSION: 1506, PROCESS: 2)"
Would a user-define PL/SQL function be okay for you?Yes.. no problem.
I'm not good with shell script, but will try show what I want using SHELL commands:
See this example:
### I create a file named "tst_string"
$ vi tst_string
ANR0166I Inventory file expiration finished processing for node OSOGBO, filespace OSOGBO\SystemState\NULL\System State\SystemState, copygroup BACKUP and object type GROUP BASE with processing statistics: examined 43, deleted 43, retrying 0, and failed 0. (SESSION: 1506, PROCESS: 2)
## So I used a function sed to get my desired values. The command bellow is poor, but My point is the result.
$ cat tst_string | sed 's/ANR0166I.*node //g' | sed 's/, filespace//g' | sed 's/, copygroup BACKUP and object type GROUP BASE with processing statistics: //g' | sed 's/. (SESSION.*//g' | sed 's/, deleted//g' | sed 's/, retrying//g' | sed 's/, and failed//g'
OSOGBO OSOGBO\SystemState\NULL\System State\SystemState 43 43 0 0The result was:
NODE FILESPACE Examined Deleted Retrying Failed
OSOGBO OSOGBO\SystemState\NULL\System State\SystemState 43 43 0 0I will go check the links wich you mentioned.
Thanks -
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... -
How to check the occurrence of a character in a string
Hello Experts,
I have a scenario where in I have to check the occurrence of a character in a string and based on that I have to pass a data into target field.
I was wondering whether this can achieved with mapping functions or Do I have to use an UDF.
Thanks in advance.
Regards
Advit RameshHi Advit,
You can achieve this by using standard function indexOf from the text category. Pass in the input string and the character value you want to check for as the input.
Standard Functions (SAP Library - SAP Exchange Infrastructure)
If the output is -1, then the character is not in the string, otherwise it is.
Rgds
Eng Swee -
How to append a character using UTL_FILE pkg
A table with student_id, student_name and date_of_join.
create table student(std_id varchar2(10),std_name varchar2(20),std_doj date);I am loading the data from the below flat file using UTL_FILE package
101 ron 04081999
101 ron 01081996
102 ram 05082000
102 ram 12101999
103 fin 06082001
104 gin 07082002
105 gem 08082003I am using a procedure to load the data into table using UTL_FILE package
Students with id's 101 & 102 have two joining dates as they have registered for two courses. In flat file there is no change in std_id but I have to append a character "C" to those who have registered for the second course.
I have to append a character to std_id column. for eg: After loading the result what I am expecting is
std_id std_name std_doj
101 ron 04081999
101C ron 01081996
102 ram 05082000
102C ram 12101999
103 fin 06082001
104 gin 07082002
105 gem 08082003 Can you please give me an idea on how to get the above result using UTL_PACKAGE in the procedure?It has nothing to do with UTL_FILE. In your load procedure you are looping through the file line by line, right? SO you need to :
DECLARE
prev_std_id number;
BEGIN
LOOP
read a line
parse it into std_id, std_name and std_doj
IF std_id = prev_std_id
THEN
std_id := std_id || 'C';
ELSE
prev_std_id := std_id;
END IF;
insert row
END LOOP;
END;SY. -
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); -
How will you locate a specific character inside a string?
Thanks in advance!!!> The best place to start with this type of question is
the documentation. Take a look at string functions:
>
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions-pt0_18.html
Absolutely.
Even if one types in "coldfusion find in string" in Google,
the first
result is on the money (for CFMX7, not CF8, but still).
Adam -
Truncating last character in a string
I am making a dialpad. It is just for display so I am using a
string for the numbers selected. I am trying to make a back button
that would clear the last number added. I tried mystring.length-1
but that doesn't seem to be doing the trick. Is there a simple way
to truncate the last character in a string, of variable
length??Here's an example
var someStr="asdfasdf saf asdf sadfas dfs fsa asf";
while (someStr.length) {
someStr = someStr.substring(0,someStr.length-1)
trace(someStr);
} -
Having the '\' character in a string
I get errors when I try to construct a string, say like this:
String blahblah = new String("IBM\ROOT\IMAGE");
Basically it seems like I can't store that '\' character in a string at all. Is this true?
Thanks in advance.the '\' character is used to indicate an escape sequence, used for things like '\n' (new line). To do what you want you can do this:
String blahblah = new String("IBM\\ROOT\\IMAGE"); //notice the double slash '\\' you would also have to do this for double and single quotes, e.g. ( new String("Bill said, \" Anne told me to \'go home now\'\"") : for... Bill said, "Anne told me to 'go home now'")
Maybe you are looking for
-
How do i put in password for outgoing server on email account
From yesterday afternoon I cannot get emails, or send them, on ipad, ipod or PC using Mozilla. On Ipad and ipod it tells me my password is wrong. I have tried re-entering password but cannot remember how to put password in for the outgoing server
-
Idoc to file scenaro ( sending IDOC as it is to NON-SAP)
Hi Experts, I am doing idoc to file scenario. I am having SAP R/3 system with 3 clients(100, 200 & 300), IDOC is comming from SAP R/3( any one of the client) In this is scenario, I am sending IDOC-XML as it is to the NON-SAP system. I heard that, i c
-
No SOAP Envelope but 1 {'}Values; HTTP 200 OK
Hi Experts, I am configuring a scneario IDOC to SOAP , Asynchronous call to an https url that is available through internet. When I try to post message to this url. I am getting following error: SOAP: call failed: java.io.IOException: No SOAP Envelo
-
Installing 64 bit mod_python on Intel
Does anyone know how to build the 64 bit Intel verson of mod_python? sudo apachectl configtest tells me this: httpd: Syntax error on line 114 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/mod_python.so into server: dlopen(/usr/
-
Active Directory / Domains
I just setup an iMac G5 on a network with a Windows 2003 domain controller. Is there a way to setup the login screen to check the username/password against the domain rather than local users?