Split string by length

studio

#1

How to split string by length 35 characters and nearest space
example : company Name: hewlett-packard singapore (private) limited
should be split to
company Name 1: hewlett-packard singapore
company Name 2: (private) limited
The first space before “limtied” comes at 36 characters …it cant be used


#2

Check this out:


#3

Hi @Badagala_Jagadeesh

Based on you requirement, please find the solution below:

  1. Create a variable as “test” string and assign your text:
    “hewlett-packard singapore (private) limited”

  2. splitIndex = (test.Substring(0, 35).LastIndexOf(" ") + 1)

  3. test.Substring(0, splitIndex) : This will return your first part

  4. test.Substring(splitIndex, (test.Length-splitIndex)) : This will return your second part

Hope this will solve your problem


Split string by whitespace
#4

Simply Super Solution with out Split …Thank you very much!

with slight syntax correction re posting it …so it might help others.

  1. Assign test= “TRAN QUANG THAI PRODUCTION TRADING IMPORT EXPORT COMPANY LIMITED”
  2. Assign splitIndex=(test.ToString.Substring(0,35).LastIndexOf(" ")+1)
  3. writeline test.ToString.Substring(0,splitindex) — This is first string
  4. writeline test.ToString.Substring(splitIndex,(test.Length-splitIndex)) — this is second string