Jump to content

Split Text at /


Recommended Posts

We have a company where users have various long, multiple part business units. If the person has more than one business unit, it is separated by a "/".


I am new to JavaScript, but managed to piece this together:


TypeSplit = Field("Title 2").split("/");

   return TypeSplit[0] +'/'+ "\n" +TypeSplit[1]+ "\n";


It does what I want, unless the person only has one business unit, in which case it returns with '/ <br> undefined'


What can I write to make one unit not have the '/' and 'undefined' ? I want it to return

" "


I appreciate any input you can offer.



Link to comment
Share on other sites

Try using a replace function instead of a split. This way it will search the string for a "/" and replace it with a break tag. I used a regex so that it can handle multiple instances of "/" thus inserted a break tag per "/".


return Field("Title 2").replace(/\//g,"<br>");

Link to comment
Share on other sites



All I had to do was add the "/" in front of the "<BR>" to get the final product we needed:


return Field("Title 2").replace(/\//g,"/<br>");


I appreciate the quick responses.



Edited by andym
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...