Problem in replacing the String in a Fille.
I need to replace the String in the text file, am able to do it partially.
I mean, am able to replace it. But there are some discrepancies if the replacement string is of "less" or "more" in length than the existing one.
I solved it for the replacement string of less size, but am unable to do it for the string of more size.. :(
The problem am facing is "when the replacement string is larger than the existing one, then the other subsequent line in the file gets overwritten".
I have used RandomAccessFile class for reading and writing the same file.
fpointer1 = randomFile.getFilePointer() - strLine.length() - 2;
strLine1 = strLine;
int sInd = strLine1.indexOf('\'');
int eInd = strLine1.indexOf(';');
String oldStr = strLine1.substring(sInd + 1, eInd - 1);
strLine1 = StringUtils.replace(strLine1, oldStr, newStr);
if (oldStr.length() < newStr.length()) {
int diff = (newStr.length() - oldStr.length()) + 1;
randomFile.writeBytes("\r\n");
for (int i = 0; i < diff; i++) {
randomFile.writeBytes(" ");
randomFile.seek(fpointer1);
randomFile.writeBytes(strLine1);
} else if (oldStr.length() > newStr.length()) {
randomFile.seek(fpointer1);
randomFile.writeBytes(strLine1);
int diff = (oldStr.length() - newStr.length()) + 1;
for (int i = 0; i < diff - 1; i++) {
randomFile.writeBytes(" ");
randomFile.writeBytes("\r\n");
break;
}Can u pls help me in resolving this issue???...
boopathi wrote:
As u said the overwriting causes the problem, but i managed to resolve for the string of less size.I assume you did this with some padding? That's not exactly a clean solution.
So thats why am seeking to manage the larger size string to replace without overwriting the sub sequent lines.
Can you help me in suggesting whether it can be resolved using the getFilePointer() and seek() methods??...No you can't.
Whether you shorten or lengthen the position where you modify the file, you need to move the remaining bytes back or forward, depending which is the case.
You managed to solve the first case by printing out padding, so you don't need to move the bytes back, but you can't solve the other case like this. You can lengthen the file and move the remaining bytes forward, but I probably wouldn't bother since a simple Reader-based approach is a lot better and easier to get right.
Similar Messages
-
I know the image can fill the monitor, because at start up, the white Apple logo screen fills it up. But once the system starts up, there are bands of black framing the image. I have searched extensively on the internet and found the following clues, none of which solved the problem:
1) In the Windows world you can get software from ATI called Catalyst Converter that gives you the cpaobility to scale the image. This software/feature is not available for Mac users.
2) Viewsonic's web site has a trouble shooting tool. This came up in response to the topic "you have recently upgraded to a larger monitor"
"This could be an issue if you have an older Apple using the system's onboard memory to support both the system and video display. Even if you have enough onboard RAM to support a higher resolution, it will not since the system will use some of the memory. Because the true video RAM available is much smaller than the total onboard amount, the system limits the size of the image. You will need to contact Apple to get an upgrade in onboard RAM or update the complete system."
I have 2GB of RAM, so lack of RAM memory does not seem to be an issue. I am running OS 10.6.8
Does anyone have any clue how to solve this problem. It is frustrating to have a 27" monitor behaving like a 25" monitor.
Thanks in advance for sharing any experience on this.
JD in PAhttp://www.xlr8yourmac.com/Graphics/radeon_X1900XT/X1900XT_dust_buildup.html#sto rytop
http://www.xlr8yourmac.com/Graphics/X1900XT_Overheating/ATI_X1900_artifacts.html
http://www.amazon.com/BUFFERED-PC2-5300-FB-DIMM-APPLE-Memory/dp/B002ORUUAC/
http://www.amazon.com/Apple-ATI-Radeon-5770-MC742ZM/dp/B003Z6QH6M/
http://www.amazon.com/PCIe-Power-Cable-nVidia-Video/dp/B002UR1654/
http://www.amazon.com/gp/product/B0036Q7MV0/ -
Problem two - replacing the fan on video card
I have a NVidea GeForce4 Ti video card in my G4. The fan cooling the GPU stopped spinning, although I don't know when. I ordered the identical fan on-line, thinking that it wouldn't be that hard to get the old fan off. Apparently, it isn't as easy as I thought. There are two black plastic pieces which springs connecting the fan/heatsink to the board. For the life of me, I can't figure out how to extract them.
So, then I thought about just removing the fan and leaving the original heat sink attached. I got 6 of the 7 screws out, but one's really tight. Assuming that I can eventually get that one out as well, I still need to extract the wires from the surface of the card... it appears that they are glued on in one spot.
Has anyone here tried changing the fan on this (or another) video card who might have some insights in how to proceed? Thanks in advance for your help!
-Anthony
Dual 1.25 GHZ G4/FW 800 Mac OS X (10.4.5)I purchased my replacement fan from "Surplus Sales of Nebraska." They actually carry the fan originally installed on the card. There website is:
www.surplussales.com
and the part number was FAN-MTHERM1027B
If you google "NV-1035-C2", it should pop right up (I get is as the first hit). They're only $6, but they have a $10 minimum order. I ended up with two fans.
I've been busy, so I haven't tried removing the fan yet. I read on the web, though, that once you remove the two black plastic pieces, you should put the video card into a freezer bag and then place it in the freezer for a few hours. Supposedly, you can then remove the fan with a twisting motion. Apparently, it's pretty easy to damage the GPU if you pull it straight off. That being said, if you can remove all of the screws on the fan, you can actually leave the heatsink in place and just replace the fan. I tried that, but I have one screw that's stuck.
Anyway, I think this is still the least of my problems. Although I haven't tried rebooting recently, I had trouble mounting a DVD today which I suspect is related to my first problem (where my hard drives don't always show up when I try to boot the computer). I'm becoming convinced that it's going to be a power supply or motherboard issue (ugh). If I get a chance to try removing the fan from the board, I'll let you know.
-Anthony
Dual 1.25 GHZ G4/FW 800 Mac OS X (10.4.6) -
How to replace the string in a file
Hi, I have a file which contains the following data
File.dat
<file>
<filenum>
W10
</filenum>
<hello>Heading </hello>
</file>
I need to replace the contents of file.dat
database sequence value (for example xx_seq.nextval)
Can some one please tell me how to search this <filenum>
W10</filenum>
and replace this with xx_seq.nextval
and write the entire contents of the file to new file
I am doing some thing like this
suppose if my database value returns 11 from the above sequence then
the output should be in file2.dat as
<file>
<filenum>
11</filenum>
<hello>Heading </hello>
</file>
declare f_in utl_file.file_type;
s_in varchar2(10000);
string1 varchar2(32000);
x number;
begin
f_in := utl_file.fopen('SAMPLEDIR','input.txt','R');
f_in1 := utl_file.fopen('SAMPLEDIR','input1.txt','W');
select xx_seq.nextval into x from dual;
loop
begin utl_file.get_line(f_in,s_in);
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
string1:= string1 || s_in;
utl_file.put_line( (f_in1,s_in);
end;
end loop;
utl_file.fclose(f_in);
end;
In this case it is reading and writing as it is, but unable to replace the sequence value
Can some one please tell me how to do using replace function
ThanksHi, I have tried this but getting error
step 1: create table test_dept(dno number, dname varchar2(20))
insert into test_dept values(10,'10-Sourcing dept');
insert into test_dept values(20,'20-Audting dept');
insert into test_dept values(30,'30-Computer dept');
select * from test_dept;
DNO DNaME
10 10-Sourcing dept
30 30-Computer dept
20 20-Audting dept
step 2:
create table test_web (name varchar2(60), xml_col xmltype) ;
step 3:
create sequence test1_seq start with 100 increment by 1
step 4:
test.out has the following contents (it is not .xml file) and i dont have <?xml version="1.0" ?> tag at the begining
<File>
<File_Type>Type1</File_Type>
<File_Header_Record>
<file_num>WP10</file_num>
</File_Header_Record>
<Transaction>
<Transaction_Type>TR 1</Transaction_Type>
<Amount>
<Amounts>100</Amounts>
</Amount>
<Depts>
<Dept_Type>Sourcing</Dept_Type>
<Dept>10</Dept>
</Depts>
</Transaction>
<Transaction>
<Transaction_Type>TR 2</Transaction_Type>
<Amount>
<Amounts>200</Amounts>
</Amount>
<Depts>
<Dept_Type>Auditing</Dept_Type>
<Dept>20</Dept>
</Depts>
</Transaction>
<Transaction>
<Transaction_Type>TR 3</Transaction_Type>
<Amount>
<Amounts>300</Amounts>
</Amount>
<Depts>
<Dept_Type>Computer</Dept_Type>
<Dept>30</Dept>
</Depts>
</Transaction>
</File>
step 5:
DECLARE
v_check_file_exist BOOLEAN;
v_file_length NUMBER;
v_block_size NUMBER;
v_file_path VARCHAR2 (100);
v_file_name VARCHAR2 (100);
v_file_type UTL_FILE.FILE_TYPE;
v_str varchar2 (32760);
v_cnt number;
v_seq number;
--check whether file exists and has data in it
BEGIN
v_file_path := '/usr/tmp';
v_file_name := 'test.xml.out';
-- initailise the variables
v_cnt := 0;
UTL_FILE.FGETATTR (v_file_path,
v_file_name,
v_check_file_exist,
v_file_length,
v_block_size);
if v_check_file_exist
then
DBMS_OUTPUT.put_line (' File exists');
IF v_file_length > 0 AND v_block_size > 0
THEN
BEGIN
select test1_seq.nextval into v_seq from dual;
insert into test_web values(v_seq,v_file_name);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.put_line ('No data found '||SQLERRM);
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('others '||SQLERRM);
END;
commit;
ELSE
DBMS_OUTPUT.put_line ('No Data in File');
END IF;
ELSE
DBMS_OUTPUT.put_line (' File Not Available');
END IF;
END;
I am getting below error
File exists
others ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML
processing
LPX-00210: expected '<' instead of 't'
Error at line 1
My requirement is to replace the
1. contents of the file WP10 from <file_num>WP10</file_num>
with sequence value 'WP101' because sequence is starting at 100
2. Replace all Dept tag <Dept>30</Dept> with Dname value from test_dept table
for example
<Dept>10</Dept> should be replaced with <Dept>10-Sourcing dept</Dept>
update the
when i say select * from test_web;
It should contain this row
101 <File>
<File_Type>Type1</File_Type>
<File_Header_Record>
<file_num>WP101</file_num>
</File_Header_Record>
<Transaction>
<Transaction_Type>TR 1</Transaction_Type>
<Amount>
<Amounts>100</Amounts>
</Amount>
<Depts>
<Dept_Type>Sourcing</Dept_Type>
<Dept>10-Sourcing dept</Dept>
</Depts>
</Transaction>
<Transaction>
<Transaction_Type>TR 2</Transaction_Type>
<Amount>
<Amounts>200</Amounts>
</Amount>
<Depts>
<Dept_Type>Auditing</Dept_Type>
<Dept>20-Audting dept</Dept>
</Depts>
</Transaction>
<Transaction>
<Transaction_Type>TR 3</Transaction_Type>
<Amount>
<Amounts>300</Amounts>
</Amount>
<Depts>
<Dept_Type>Computer</Dept_Type>
<Dept>30-Computer dept</Dept>
</Depts>
</Transaction>
</File>
Can you please check
Thanks -
Problem in converting the String to Date with time zone GMT
Hi,
When I tried to convert the string 12/05/2009 to Date, the time zone is set to BST.On the other hand, for the date 12/12/2009, the time zone is set to GMT. What should I do to get the time zone as GMT all the time.?
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String dateString = "12/05/2009";
System.out.println(myDate.toString());I think you are all missing the point. java.util.Date objects always alway always store the date as the number of milliseconds since 1/1/1970 UTC so the only TimeZone they have its the implicit UTC. When you use the Date.toString() method the toString() method gets the default time zone from your environment and formats the data accordingly. This means that the same Date object will, by default, produce a different result for France and Australia and the US.
So, if you have the date "12/5/2009" as a String then to convert it to a java.util.Date you must specify what TimeZone is implied. If it is your system time zone then you can just create a SimpleDateFormat object with the correct format and then use the parse() method to create the java.util.Date object and this will automatically be converted to UTC. If the date String represents some other time zone then you must explicitly set the time zone of the SimpleDateFormat object before parsing the string.
The same approach applies when converting a java.util.Date object to a String. If you want anything other than your system time zone then you must explicitly tell the SimpleDateFormat what time zone you want the result formatted for. -
Problems after Replacing the Main Logic Board in E280R
Hi
I have just replaced the main logic board and FCal Disk Back plane in one of our E280Rs and now we cannot get any out put to a console (or to RSC card). So cannot get to the OK prompt or any diagonistic output. There are no errors according to the system lights although the RSC card is reporting faulty internal disks. Whether the disks or working or not we still should be be getting at least to the OK prompt.
The main logic board has the same part number as the one we replaced and we swapped the old SEEPROM chip to the new main Logic board
Any Suggestions greatfully received
Thanks
RobLowLuster is correct.
If Apple techs are talking about replacing the logic board, the costs of doing so is over half the cost of a newer IMac.
You maybe better off, if it is financially possible for you, to purchase a new or "newer" used or refurbished iMac. -
Replacing the string with a sbstring
String query="elect empname,empDate,CustNo from EmpData where (empname='smith') and ( empDate> '22/10/2005' and CustNo > '1' )";
the date here is dd/mm/yyyy formatt..
i want extract that date and change it to mm/dd/yyyy formatt and re create the same query with changed date due to some contraints in my application.not only this date i may get more dates cause its generated dynamically..
how can achieve this..
Regards,thanks,
its not about jdbc..some times the user may enter the arabic dates.i will decide wther its arabic year are english year based upon the year digit.so if it is arabic year then i have to find the appropriate gregorian date based upon the arabic date.because in date base we store only grergorian dates..for this case iam asking for this..if found any arabic date then i will replace that date with appropriate gregorian date..i need to know how can replace this..i have the functionality for converting the arabic date to gregorian.
regards, -
How to replace the string of column value with other column value in same table
I have a temp table which contains
Id Name CTC Address Content
1 Ross $200 6th block Dear #Name your CTC is #CTC and your address is #address
2 Jhon $300 1oth cross Dear #Name your CTC is #CTC and your address is #address
Now i want to select content so that it should get replace with the respective columns and final output should come like this
Dear Ross your CTC is 200 and your address is 6th block
Dear Jhon your CTC is 300 and your address is 10th cross
Kindly suggestI think RSingh suggestion is ok ... what do you mean by another way? ...maybe something more generic?
maybe build a table whith the list of col you need to "replace" and dinamically build the replace query ...
declare @colList table(colName varchar(100))
insert into @colList
select 'name'
union all select 'ctc'
union all select 'address'
declare @cmd varchar(2000)
select @cmd='select '+ (select 'replace(' from @colList for xml path('') +' content '+
(select ',''#'+ colName +''', '+ colName +')' from @colList for xml path(''))
+' from YOURTABLENAME '
exec (@cmd)
or your request was different ? -
Need to replace the string that contains '|' character using replaceFirst
I have the code snippet like this
String aaa= "HEY | PRAKASH, HOW ARE YOU";
String bbb = aaa.replaceFirst("HEY | PRAKASH", "HI");
System.out.println(bbb);
I want the output as
HI,HOW ARE YOU
But the output I am getting is "HI| PRAKASH, HOW ARE YOU"
Wat is the issue with '|' symbol, is there any way to achive this......String aaa= "HEY | PRAKASH, HOW ARE YOU";
String bbb = aaa.replaceFirst(java.util.regex.Pattern.quote("HEY | PRAKASH"), "HI");
System.out.println(bbb); -
Even after deleting the string "Counting to five: one 2 three 4. five." from the string control and replacing it with another string the original string returns after the VI is saved then reopened. Where is this string data coming from? I've attached a copy of the library function. I've been able in my application to get around the problem by replacing the string control with a string constant. But I'm still curious as to what's going on.
Thanks,
Chuck
Solved!
Go to Solution.
Attachments:
Extract Numbers Test.vi 9 KBChuck,
String control has been set to default with the string you are seeing. To change this, enter the new string, right click the control and select
Data Operations>>Make Current Value Default
Now save your vi. -
For PostUUT in the NI teststand II courese example 4-1 Modifying callback.seq, there are two steps, one is Test Passed,
the other is Test Failed, both set each preconditions, for example, Parameters.Result.Status == "Failed" in the test failed step, if the step failed in the main sequence,the string "failed " is filled into Parameters.Result.Status
but I can't find where the string "failed" is created in steps in the main sequence.
Because I can't find any expression in any steps to fill into Parameters.Result of the test failed step in the PostUUT.
In fact, when running if step fails, the string "failed " is filled into Parameters.Result.Status
Would you please explain for it ?
thanks,Hi,
Look at the Sequential Model Sequence File, and either the sequence SinglePass of Test UUTs for the step that invokes the step Post UUT.
Then look at the Parameter List for the SequenceCall for that step. you will find your answer.
Regards
Ray Farmer -
Replacing a string of character by another one with emacs
Hello,
With Vim, I had something like this in my setup (tex.vim in ftplugin)
imap <buffer> ... \ldots
imap <buffer> « \og
imap <buffer> » \fg
imap <buffer> " \textquotedblleft
imap <buffer> ¢ \textquotedblright\
imap <buffer> € \EUR
imap <buffer>~ $\sim\
imap <buffer> // \\
imap <buffer> /np \newpage
Currently, I am trying emacs, and would like the same setup. I have searched the web, but with no luck. Indeed, I've just found the following code (and made some modifications to try it) :
(defun replace-string-pairs-region (start end mylist)
"Replace string pairs in region."
(save-restriction
(narrow-to-region start end)
(mapc
(lambda (arg)
(goto-char (point-min))
(while (search-forward (car arg) nil t) (replace-match (cadr arg)) )
) mylist
(defun replace-chars (start end)
"Replace "..." by "\ldots" and other similar chars"
(interactive "r")
(replace-string-pairs-region start end '(
("..." "\ldots")
;("<" "<")
;(">" ">")
But it doesn't work.
Does anyone know how could I replace "..." by "\ldots" and other things like that with Emacs ?
Last edited by alexandre (2010-09-28 17:48:50)Thank you a lot for your answer, but my problem was not to replace "..." by "\ldots" after typing it, but how could I replace "..." by "\ldots" while I am typing it, just after I finished to push the last dot.
I have tried to set it up with the abbrev mode, but it seems to work only for words. So for example, if I enter the word such as, say, "arch", then it replace it automatically by "archlinux" after pressing the space key. I won't have to replace the string manually, it does it automatically with the abbreviation mode of Emacs. Here is an example of what I am talking about :
(abbrev-mode t) ; completion automatique
(global-set-key (quote [tab]) (quote dabbrev-expand))
(setq default-abbrev-mode t)
(define-abbrev-table 'global-abbrev-table '(
("..." "\ldots" t)
("arch" "archlinux" nil)
But my problem is, it doesn't work for "...", just for words. Of course, I could do it manually with the shortcut you wrote, but it would be nice to make it work automatically. Is there a way to do so ?
If you don't understand what I am talking about, try Vim, copy "imap <buffer> ... \ldots" in your .vimrc, and Vim will replace all "..." by "\ldots" while typing. I am sure I can do it with Emacs, I just don't know how.
Last edited by alexandre (2010-09-30 12:28:38) -
Replace a string except it was replaced
Hey guys:
I met a big problem and would you guys do me a big favour?
I want to replace a part of a text String by some other Strings.
for example,I want to replace the String "ab" into "cd",and the String "cd" into "xx" from the text "abcdefg", and what I expected result is "cdxxefg",but if i call the methodYou rperformance has been praiseworthy. Andthere's
no one else to blame but you :)I agree. And, may I please take the blame foryour
typo?It's a conspiracy... that space moved after I posted.
Blame it on... dunno who :)Got to let this poor OP get back to his/her thread, but , keep on blaming it on me. I am a conspiracy all on my own.
RD-R
� {� -
I have the following string:
String="TVBeginEsternTVEnd
MovieBeginN/AMovieEnd
TVBeginPacificTVEnd
MovieBeginN/AMovieEnd......................"
I need to replace only the contents between TVBegin and TVEnd. The result (If I want the content=Midwest) should look as follow:
String="TVBeginMidwestTVEnd
MovieBeginN/AMovieEnd
TVBeginMidwestTVEnd
MovieBeginN/AMovieEnd......................"
Do you have any suggestions on how to replace the string content?
Thank you very much!Sheshy,
We can tell you how to do small things, one at a time, all day long. You really need to learn how to read the documentation. Go read the documentation for String, StringBuffer. You can figure it out. Really. -
Hi,
I have the problem to create the String with the lenght longer than 2 MBytes.
For instance :
byte[] b = new byte[10*1024*1024);
len = b.length;
String s = new String(b,0,len);
Any helps are appreciated.
PS: Pls assume b contains a data e.g. 7*1024*1024 and has the length of 7*1024*1024, everthing is ok until the String can not be instanstiated.
Regards
PaulusI have the problem to create the String with the lenght longer than 2 MBytes.What do you mean - what kind of problem? This works just fine:public class test {
public static void main(String args[]) {
byte[] b = new byte[10 * 1024 * 1024];
for (int j = 0; j < b.length; j++) {
b[j] = 97;
String s = new String(b) + "b";
System.out.println(s);
}(although running did require setting the max. heap size bigger... :)
Maybe you are looking for
-
Error in Init method - Component (blank)
Hello, I am getting the following error and the component that has an error is not listed. Any ideas what might cause this? In this case I have an iView opening a KM repository. The iView works when previewed but it fails when added to a page. [EXC
-
Designer 6i R4.1.1 - orainst.exe - Application Error
Setup.exe fails after the first 4-5 with application memory error: The application, , generated an application error The error occurred on 01/17/2002 @ 15:30:32.740 The exception generated was c0000005 at address 00F7071E (<nosymbols>) Any sugestions
-
My Macbook (2.0 GHZ, 1 gb ram, superdrive) won't turn on correctly. When I turn it on, it says "/ect/master/passwd: No such file or directory -Sh-2.05 b# IOBluetoothHCIController::startIdleTimeStopped". I have Boot Camp installed with Vista pre-RC1,
-
Older xcode for older machine?
trying to install something that wants xcode 3.2.6 but can't find it. the only links i find take me to a loop of putting in my id and password but never to a downloads page. is 3.2.6 available anywhere anymore? thanks, BabaG
-
Suggestion for dbus, hal. new gnome-volume-manager-version.
Heya, I just installed dbus, hall from cvs and gnome-volume-manager from tarball and have some suggestions: dbus: the default during configure seems to be to detect if you have the necessary things installed and based on that enable a component. To d