473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HELP: Simple recursive function

I am trying to create a function which strips out ALL occurances of a
particular phrase in a string. It returns the cleaned up string. I gave it
an argument of "1###2###3###4". When it finally gets to the Return
statement it DOES return the correct thing, but by the time it finally
"unravels" it returns nothing. Any ideas????

Private Function StripOutPounds(ByVal strMsg As String) As String
Try
Dim s As String

' strip out every occurance of "###"
If strMsg.IndexOf("###") <> -1 Then ' if an occurance exists
' get everything to the left
s += strMsg.Substring(0, strMsg.IndexOf("###"))
' get everything to the right
s += strMsg.Substring(strMsg.IndexOf("###") + 4)
s = StripOutServerMessage(s)
Else ' return cleaned up message
Return strMsg
End If
End Function
Nov 20 '05 #1
4 1354
Never mind. Instead of "s = StripOutServerMessage(s)" I put "Return
StripOutServerMessage(s)" and it worked!

Thanks.

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am trying to create a function which strips out ALL occurances of a
particular phrase in a string. It returns the cleaned up string. I gave it an argument of "1###2###3###4". When it finally gets to the Return
statement it DOES return the correct thing, but by the time it finally
"unravels" it returns nothing. Any ideas????

Private Function StripOutPounds(ByVal strMsg As String) As String
Try
Dim s As String

' strip out every occurance of "###"
If strMsg.IndexOf("###") <> -1 Then ' if an occurance exists ' get everything to the left
s += strMsg.Substring(0, strMsg.IndexOf("###"))
' get everything to the right
s += strMsg.Substring(strMsg.IndexOf("###") + 4)
s = StripOutServerMessage(s)
Else ' return cleaned up message
Return strMsg
End If
End Function

Nov 20 '05 #2
Cor
Hi VB programmer,

Why not

return replace(strMsg,"###","")

is that not something more simple?

Cor
I am trying to create a function which strips out ALL occurances of a
particular phrase in a string.

Nov 20 '05 #3
For this particular example, I am wondering why you did not do something
like:

Private Function StripOutPounds(ByVal strMsg As String) As String

Return strMsg.Replace("###","")

End Function

Unless you are trying to use recursion, the Replace method is much simpler.
Perhaps:

strMsg.Replace("#","")

is better.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"VB Programmer" <gr*********@go-intech.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am trying to create a function which strips out ALL occurances of a
particular phrase in a string. It returns the cleaned up string. I gave it an argument of "1###2###3###4". When it finally gets to the Return
statement it DOES return the correct thing, but by the time it finally
"unravels" it returns nothing. Any ideas????

Private Function StripOutPounds(ByVal strMsg As String) As String
Try
Dim s As String

' strip out every occurance of "###"
If strMsg.IndexOf("###") <> -1 Then ' if an occurance exists ' get everything to the left
s += strMsg.Substring(0, strMsg.IndexOf("###"))
' get everything to the right
s += strMsg.Substring(strMsg.IndexOf("###") + 4)
s = StripOutServerMessage(s)
Else ' return cleaned up message
Return strMsg
End If
End Function

Nov 20 '05 #4
* "VB Programmer" <gr*********@go-intech.com> scripsit:
s += strMsg.Substring(0, strMsg.IndexOf("###"))


Only FYI: In VB.NET, it's recommended to use the '&' or '&=' operator
to concatenate strings.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: actuary77 | last post by:
I am trying to write simple recursive function to build a list: def rec(n,alist=): _nl=alist print n,_nl if n == 0: print n,_nl return _nl else:
9
by: JP SIngh | last post by:
Hi All I am trying to write a recursive function to list the managers and his employees in a tree like sctructure Manager 1 Emp1 Emp1.1 Emp 1.2 Emp 2
2
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
8
by: ali | last post by:
Hi, I'm trying to work on a recursive function that will give me root valuefor a given number. What i mean by root value is, if given 13, the answer is 1+3 = 4. If given 65, the answer is 2,...
4
by: Ryan Ternier | last post by:
I have a section of my project that is Driving me nuts. No one has been able to help that much on it, so i thought of posting it here in hopes someone could help. I need to print out an...
4
by: pauldepstein | last post by:
I am writing code to price some financial options using recursive functions. It compiles but I get a runtime error which is caused by a memory violation. The problem is that the code is much...
0
by: Michael L | last post by:
Hi Guys(I apologize for the lengty post - Im trying to explain it as best i can) I've been cracking my head on this one for the past 24+ hours and i have tried creating the function in ten...
4
by: rumbylove | last post by:
Could I please have the solutions to the following problems 1. (4 points) Your friend has to write code to make sure that the parentheses in an arithmetic expression are balanced, i.e. for every...
9
by: pereges | last post by:
Hello I need some ideas for designing a recursive function for my ray tracing program. The idea behind ray tracing is to follow the electromagnetic rays from the source, as they hit the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.