Source language: Translate to:

Character Replacement issues?

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Character Replacement issues?

Postby dcavern » Sat Feb 27, 2010 9:05 am

My goal is to pull strings out of a db and format to print. I'm trying to replace the pipe (|) with an actual CR/LF. Missing something probably obvious.

I have some stuff before this so the file is created correctly and the data before this is inserted fine, but this

StrReplace "[stor.thedata]" "|" "[#13]" "[new]" ""
FileWrite "[PubDir]rtemp" "Append" "[new]"

doesn't seem to work as I think it would.

I've also used [#124] in place of | and achieve same result. The outputfile contains the | character just as it does in the db record.

Help?

Thanks,
kevin
dcavern
 
Posts: 8
Joined: Wed Dec 30, 2009 9:24 pm

Postby Gaev » Sat Feb 27, 2010 10:34 am

Kevin:

First, try ...
Code: Select all
StrReplace "[stor.thedata]" "!|" "[#13][#10]" "[new]" ""

If that doesn't do the job, see if the pipe character is actually present in the field ...
Code: Select all
SearchStr "!|" "[stor.thedata]" "[PipeePos]" ""
Alert "Pipe Position" "[PipePos]"

If the pipes exist ... and it still does not save properly ... you might try and repleace the FileWrite command with ...
Code: Select all
FileRead [PubDir]rtemp" "All" "[old]"
If "[old]" "<>" ""
  FileWrite "[PubDir]rtemp" "All" "[old][#13][#10][new]"
Else
  FileWrite "[PubDir]rtemp" "All" "[new]"
EndIf
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby dcavern » Sat Feb 27, 2010 5:37 pm

Thanks for the speedy reply Gaev.

> StrReplace "[stor.thedata]" "!|" "[#13][#10]" "[new]" ""

I did try this before I posted. With the !. I saw that in another post you had made :)

It's not the output that's the problem because the newstring is not altered. It's basically doing a strcopy as the newstring is the same string it's pulling out of the db as evidenced by the pipes being written with the filewrite command....

Here's my scenario....

The user inputs a list via my app. say for example:

This is the first item
Here is the next item
And the last item

At the end of each line they hit Enter so the string saved to the db looks like this:

This is the first item|Here is the next item|And the last item

So at a later time, or for another user, I wish to print the list entered earlier. I wish to format the output as it was entered instead of one long string. That is, I want it to print as I typed it above.

My (probably flawed) logic says write it to a file, then print the file, then delete the file.

When I run StrReplace and filewrite [new], it writes to the file exactly as it comes out of the db.

Almost like it's just copying the string out of the db to [new] ....
dcavern
 
Posts: 8
Joined: Wed Dec 30, 2009 9:24 pm

Postby dcavern » Sat Feb 27, 2010 5:59 pm

I neglected to mention....these strings are being pulled from a field of type MEMO....I don't know if that matters.....
dcavern
 
Posts: 8
Joined: Wed Dec 30, 2009 9:24 pm

Postby Gaev » Sat Feb 27, 2010 6:12 pm

Kevin:
The user inputs a list via my app. say for example:

This is the first item
Here is the next item
And the last item
Does the user enter this into a Multi Line Text Entry Box ?
the string saved to the db looks like this:

This is the first item|Here is the next item|And the last item

When I run StrReplace and filewrite [new], it writes to the file exactly as it comes out of the db.
a) Is that "[stor.thedata]" ? ... a database field has to be of the format [ID.Table.Field]

b) Did you try the FileWrite with the "All" option ? ... could be that the StrReplace is doing its job ... but the FileWrite command that follows (with the "Append" option) is undoing it.

If that does not do it ... see my other recent post where I suggest you look at the contents using a Hex Editor ... so you can examine in more detail what the "|" character represents.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby dcavern » Sat Feb 27, 2010 7:43 pm

Gaev,

Again, thank you.

The "All" option DOES behave the way I expect, formatting the output file correctly.

My problem is that this list is not the only piece of info I need to filewrite so when I filewrite the second piece of course the first part of the file which I've already constructed, is replaced (as its supposed to be with 'All'.)

Is there a better way than I'm attempting? Im trying to pull two strings and format them so they will print with the CR as the user enters it.

Yes it is a multi line text entry box taking the input. And I'm using NeoBookDB. Maybe I need to look at NeoBookDBPro... and I haven't even bought the full NeoBook yet (but already decided I will)

Thanks for your help!!
dcavern
 
Posts: 8
Joined: Wed Dec 30, 2009 9:24 pm

Postby Gaev » Sat Feb 27, 2010 8:46 pm

Kevin:
My problem is that this list is not the only piece of info I need to filewrite so when I filewrite the second piece of course the first part of the file which I've already constructed, is replaced (as its supposed to be with 'All'.)
Look at my last point in the first post ... you read the existing content and write back the existing content PLUS the new content (again using the "All" option) ... note that you have to allow for cases when the existing content does not exist ... depending on your Application design, you may have to do a FileExist instead of checjing for an empty content.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby dcavern » Mon Mar 01, 2010 7:59 am

Gaev,

Your last point in your first post was EXACTLY my solution.

In fact, using this logic, I re-wrote a couple of other actions I had been
doing and things are performing much smoother and predictable now.

Thank you so much for helping me to get past my tunnel vision!

You are a wonderful asset to this forum!

kevin
dcavern
 
Posts: 8
Joined: Wed Dec 30, 2009 9:24 pm


Return to NeoBook Action Commands

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests