How to split an address to a new life if it is too long?

How to split an address to a new life if it is too long?

For eg:

ahsdhasdh asdhashdah ae3asdas asd 32 asdhasdhas

this is my address…

Using LINQ Query, I need to split this address into new lines if the length is greater than 20.
It will check to see if there is space on the 20th character, and if there is, it will split to the new line.

Hi,

Can you try the following expression?

yourString.Split(" "c).Aggregate(Function(x,s) if((x.Split(chr(10)).Last()+" "+s).Length<=20,x+" "+s,x+vbcrlf+s))

Regards,

Yes, it works, but how can I divide it into only two lines?

Hi,

Is it no problem if length of 2nd line is greater than 20?
If yes, the following regex will work

System.Text.RegularExpressions.Regex.Replace(yourString,"^(.{0,20}) ","$1"+vbcrlf)

Regards,

1 Like

Thank you for youe help :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.