in my application i need a function which takes input a string and a numeric value
and i need to have the return type of the function checking weather the input string i having moure characters then the input number
if so it should display the string in two different lines
a sample code
Dim
b As String = setline("adf dasf adsfa adf dfa", 5) 'calling function setlineMsgBox(b)
Private
Function setline(ByVal input As String, ByVal len As Int16) As String If input.Length > len Then 'checking weater the input char is moure than the lenReturn input
input = input.Chars(len) & Environment.NewLine & input.Chars(len) 'spliting into diff lines
Else Return input End If End Function
but this is showing some error
can u help plz

in my application i need a function which takes input
imed-deborah
Hi Rajesh
I don't follow the connection between your question and the VSTO technology This forum isn't for general programming questions, just for VSTO-related discussions.
FWIW, if you have Return input before the calculation, it won't return what you have in the calculation. You need to have Return input at the END.
If you're getting an error message, you need to quote the exact error message when asking for help. Everyone here is just as busy with work as you are and doesn't have time to spend trying to recreate what you're doing. You have to provide as much information as possible.
I'm moving this thread to a VB.NET forum, since that appears to be the language you're using. Please provide the error message you're getting so that the folks there can follow-up with you.
ivods
Hi
How do you want the format of the input string to be returned. Is it simply, if the length of the input is greater than the len value (5 in this example) then the string should contain the first five characters followed by a carriage return and the remaining characters Also, in the example you provided you are using the Chars property of the input string but char only returns a single character at a specific index within the string, is this what you intended
Assuming you did want to break the string into two lines and seperate the first string immediately after five characters then maybe the following will be of use:
Private Function setline(ByVal input As String, ByVal len As Int16) As String
If len > input.Length Then
Return input
Else
Return input.Substring(0, len) & ControlChars.Cr & input.Substring(len, input.Length - len)
End If
End Function
If this doesn't help, could you elaborate on what you expect the setline function to return.
HTH
Brian Rogers
Thanks for ur coding
but this is not my requirement
my requirement is to split the given string into number of small strings of given length of chars and display in new lines
eg
patrick anguet
Here's one way:
Dim b As String = setline("adf dasf adsfa adf dfa", 5) 'calling function setline
MsgBox(b)
Private Function setline(ByVal input As String, ByVal len As Int16) As String
If input.Length <= len Then 'checking weater the input char is moure than the len
Return input
Else
Dim output As New StringBuilder
For i As Integer = 1 To input.Length
output.Append(input.Substring(i - 1, 1))
If ((i Mod len) = 0) Then output.Append(Environment.NewLine)
Next
Return output.ToString
End If
End Function