0
char[] delimiterChars = {'-'};
string text = "123-45-6789"
string[] words = text.Split(delimiterChars);
foreach (string s in words)
{
  pdfFormFields.SetField("PutItHere: ", s);
}//foreach


Result: 
PutItHere: 6789

I want it to be like "123456789" , I dont know how to manipulate and put it like that. Pls help.

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101
Ping
  • 41
  • 6

2 Answers2

5

I think you should have used Replace instead

string text = "123-45-6789";
text = text.Replace("-", String.Empty);
Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • 1
    Suggestion: for readability a lot of developers prefer `string.Empty` versus `""`.to make reading code look more *fluent*. ;) – Gigabyte Jan 06 '17 at 08:47
  • should be `string` not `String` – Phill Jan 06 '17 at 08:50
  • How can I mark this as answer? Thanks a lot @MohitShrivastava – Ping Jan 06 '17 at 08:52
  • @MohitShrivastava no, `string` is nothing more than an alias of `String`, and the alias should be used. – Phill Jan 06 '17 at 09:02
  • @Phill I do agree with you. What I meant to say has been explained in detail here on [difference between String and string](http://stackoverflow.com/a/7077/3796048). – Mohit S Jan 06 '17 at 09:06
0

Any particular reason you want to use Split()?

If you have to use Split and put into a loop, you have to create a variable and concat each splitted string as the end result.

Also, pdfFormFields.SetField() need to put outside the loop. Otherwise the result will be replaced in each loop.

string result = string.Empty;
foreach (string s in words)
{
  result += s;
}//foreach
pdfFormFields.SetField("PutItHere: ", result);
Koo SengSeng
  • 933
  • 3
  • 12
  • 31