| View previous topic :: View next topic |
| Author |
Message |
sylvaticus Power User

Joined: 15 Jun 2006 Posts: 50
|
Posted: Mon Apr 27, 2009 1:32 am Post subject: Basic: replace text in a String (not a document) |
|
|
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 ??  |
|
| Back to top |
|
 |
sylvaticus Power User

Joined: 15 Jun 2006 Posts: 50
|
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Mon Apr 27, 2009 10:16 pm Post subject: |
|
|
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 |
|
 |
|