OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Basic: replace text in a String (not a document)

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
sylvaticus
Power User
Power User


Joined: 15 Jun 2006
Posts: 50

PostPosted: Mon Apr 27, 2009 1:32 am    Post subject: Basic: replace text in a String (not a document) Reply with quote

Hello.. a very "basic" question.. how can I replace a substring in a string using Basic?
I want replace all "_" with spaces.. I was looking for a native oooBasic string "replace" method, but I could not find any (!!!! ahhh Basic !!!!).
I found then the createReplaceDescriptor, but it looks it's for a whole document.
Finally I hear about embedding Javascript.. but it looks overcomplicated for my case.

So, basically, how can I replace a substring in a string using Basic ?? Sad
Back to top
View user's profile Send private message
sylvaticus
Power User
Power User


Joined: 15 Jun 2006
Posts: 50

PostPosted: Mon Apr 27, 2009 2:29 am    Post subject: Reply with quote

Found (and tested) here:
http://www.oooforum.org/forum/viewtopic.phtml?p=73061#73061
(function StrSubstitute)
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Mon Apr 27, 2009 10:16 pm    Post subject: Reply with quote

Hi,
The replaceAll routine replaces every occurence of a substring in a string.
Code:

Option Explicit

Sub Main
Dim s as string
s = "This_is_an_example"
replaceAll(s, "_", " ")
print s
End Sub

Sub replaceAll(myString As String, str1 As String, str2 As String)
myString = join(split(myString, str1), str2)
End Sub

______
Bernard
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group