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 Likes
Check this out:
Based on you requirement, please find the solution below:
-
Create a variable as “test” string and assign your text:
“hewlett-packard singapore (private) limited” -
splitIndex = (test.Substring(0, 35).LastIndexOf(" ") + 1)
-
test.Substring(0, splitIndex) : This will return your first part
-
test.Substring(splitIndex, (test.Length-splitIndex)) : This will return your second part
Hope this will solve your problem
4 Likes
Simply Super Solution with out Split …Thank you very much!
with slight syntax correction re posting it …so it might help others.
- Assign test= “TRAN QUANG THAI PRODUCTION TRADING IMPORT EXPORT COMPANY LIMITED”
- Assign splitIndex=(test.ToString.Substring(0,35).LastIndexOf(" ")+1)
- writeline test.ToString.Substring(0,splitindex) — This is first string
- writeline test.ToString.Substring(splitIndex,(test.Length-splitIndex)) — this is second string
1 Like