Service Desk Practitioners Forum
cancel

How to parse new line for text entered into Information field?

Highlighted
GunMetalGrey
Regular Contributor.

How to parse new line for text entered into Information field?

Hi guys, I'm trying to create a new service call via the web api, and in doing so I need to enter text into the information field that I received from a posted html form. How do I parse new lines in the text? as it comes through as one big concatenated string?!?..

ie.

This is a test
of a new line
1
2
3

comes thru as :
This is a testof a new line123

I've tried adding /r/n, /n, to the strings but to no avail.

thanks in advance

Jason
6 REPLIES
Ganesha Sridhar
Outstanding Contributor.

Re: How to parse new line for text entered into Information field?

Hello Jason,

The working code is attached which addresses your problem.

In the code insted of \n use
String newline = System.getProperty("line.separator");

The description is available at:
http://java.sun.com/j2se/1.3/docs/api/java/lang/System.html
(In the page find string - line.separator)

HTH

Regards
Ganesha Sridhara

GunMetalGrey
Regular Contributor.

Re: How to parse new line for text entered into Information field?

Ganesha

I'm setting the information field as a "string" which I'm passing through via a web service from asp.net. So thus I construct my string on the .net codebehind , eg.

sInformation = "Name:" & sName & _
"Phone:" & sPhone & _
"Address:" & sAddress

is there any way to pass the newline character through this way from .net? or will I have to do a replace of all "chr(13)"'s or something once I receive the string ont the java end?

thanks

Jason
GunMetalGrey
Regular Contributor.

Re: How to parse new line for text entered into Information field?

Hi I'm still having a problem with this. I was wondering if anyone has any code that shows how to convert line breaks from a windows platform to those from java?

also I'm forced to use Java 1.3.0 which doesn't have replaceAll() :(.. is there any other way around it?

I could really try and push the client to upgrade to 1.4.2 but I'm thinking it might be quite tough.
Mark Teichmann
Super Contributor.

Re: How to parse new line for text entered into Information field?

can't you use vbNewline or something in .NET? Do you use VB or C#?
Or can you use Chr(10) + Chr(13) ?
GunMetalGrey
Regular Contributor.

Re: How to parse new line for text entered into Information field?

I'm building the string with vbNewlines in vb.net and then passing this string through to the web service. I will need to have it display properly in the "information" field within service desk. It then gets used in an external data update trigger which calls a .net page and passes the relevant fields to that which then sends an email containing these fields.

so basically it goes from vb.net --> Java --> back to vb.net

but yeah I've tried everything.. vbnewline, chr(10), chr(13), etc they all don't show up correctly within the information field. I was then thinking to try and search for these characters and replace them with /n's when i do the creation of the service call.. but being limited by java 1.3.0 i couldn't find a solution (ie no replaceall())..
GunMetalGrey
Regular Contributor.

Re: How to parse new line for text entered into Information field?

I finally managed to solve my problem.

For those who may be in a similar situation in the future this is the solution that I used:

Basically I would replace all the VBnewLines when passing the string through to the webservice with my own custom string character, in this instance "jCrLf".

On the Java side (web service) I would then use the following code to replace the jCrLf markers with '\r\n'

public String getLineBreakString(String psString){
String tempString;
String newString;
StringBuffer sb = new StringBuffer();

tempString = psString;

int pos;

pos = tempString.indexOf("jCrLf");
while(pos >= 0){
sb.append(tempString.substring(0,pos) + "\r\n");
tempString = tempString.substring((pos + 5));
pos = tempString.indexOf("jCrLf");
}
if(tempString.length() > 0) {
sb.append(tempString);
}

newString = sb.toString();
return newString;
}